user3054023
user3054023

Reputation: 127

Nginx + Varnish 4 return 200 empty response for all requests

I have nginx as a front end reverse proxy + varnish cache + web app backend set up, requests are going through nginx - > varnish - > backend, i can see logs at all sides, but it returns a blank 200 response for all requests.

my /etc/default/varnish.vcl

vcl 4.0;


backend jira {
    .host = "127.0.0.1";
    .port = "27988";
}


sub vcl_recv {

   set req.backend_hint = jira;

   if (req.url ~ "\.(png|gif|jpg|swf|css|js)$") {
      unset req.http.Cookie;
      return (pipe);
  } else {
      return (pass);
  }

}


sub vcl_backend_response {

    if (bereq.url ~ "\.(css|js|jpg|jpeg|gif|png|ico)$") {
        unset beresp.http.set-cookie;
        set beresp.ttl = 30m;

     #Set Grace Time to one hour
       set beresp.grace = 1h;
    }
}

my nginx conf

server {

    listen 80;
    server_name jira.lan.mysite.com;

    location / {
        proxy_pass      http://127.0.0.1:6081/;
        proxy_set_header        X-Real-IP       $remote_addr;
        proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header        Host $host;
    proxy_set_header    X-Forwarded-Proto   $scheme;


    }

}


80 - nginx port
6081 - varnish port
27988 - backend server(jira) port

requests to jira.lan.fongwell.com go to nginx first, then varnish , then backend if not static resources, but all return empty 200 response.

If I bypass nginx and go to varnish, eg. 192.168.0.119:6081, where 6081 is varnish port, then things work ok!

the http response header returned on the browser

Accept-Ranges   bytes
Age 0
Cache-Control   no-cache, no-store, must-revalidate
Connection  keep-alive
Content-Encoding    gzip
Content-Length  0
Content-Type    text/html;charset=UTF-8
Date    Fri, 11 Dec 2015 01:50:57 GMT
Expires Thu, 01 Jan 1970 00:00:00 GMT
Pragma  no-cache
Server  nginx/1.4.6 (Ubuntu)
Set-Cookie  JSESSIONID=C49D71942379289A803041B4257E6328; Path=/; HttpOnly
Vary    User-Agent
Via 1.1 varnish-v4
X-AREQUESTID    110x16852x1
X-ASEN  SEN-L4572887
X-AUSERNAME anonymous
X-Varnish   32779
x-content-type-options  nosniff

what's wrong with my settings? Thanks

Upvotes: 2

Views: 2300

Answers (1)

Cesc
Cesc

Reputation: 688

Have you tried this?

server {

listen 80;
server_name jira.lan.mysite.com;
...
  location / { 
    ...
    proxy_http_version 1.1;
    ...
  }
}

I had a similar issue and the problem was that nginx was using http/1.0 protocol as reverse proxy and looks this can't handle much well encoded chunk stuff.

Upvotes: 4

Related Questions