Tomcat Nginx+;Varnish 4为所有请求返回200个空响应

Tomcat Nginx+;Varnish 4为所有请求返回200个空响应,tomcat,nginx,varnish,Tomcat,Nginx,Varnish,我将nginx作为前端反向代理+varnish缓存+web应用程序后端设置,请求通过nginx->varnish->backend进行处理,我可以看到各个方面的日志,但它会为所有请求返回一个空白的200响应 my/etc/default/varnish.vcl vcl 4.0; backend jira { .host = "127.0.0.1"; .port = "27988"; } sub vcl_recv { set req.backend_hint = j

我将nginx作为前端反向代理+varnish缓存+web应用程序后端设置,请求通过nginx->varnish->backend进行处理,我可以看到各个方面的日志,但它会为所有请求返回一个空白的200响应

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;
    }
}
我的nginx配置

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
对jira.lan.fongwell.com的请求首先进入nginx,然后是varnish,如果不是静态资源,则进入后端,但都返回空的200响应

如果我绕过nginx进入varnish,例如
192.168.0.119:6081
,其中
6081
是varnish端口,那么一切正常

浏览器上返回的http响应标头

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
我的设置有什么问题?谢谢你试过这个吗

server {

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

我有一个类似的问题,问题是nginx使用http/1.0协议作为反向代理,看起来这无法处理很多编码良好的区块内容。

不确定这是否是您问题的原因,但我非常确定您希望在VCL中对静态内容使用return(查找)和Not return(管道)。感谢您的回复,我正在使用varnish 4,在子例程“vcl_recv”中说“Invalid return”lookup,合法的返回是:“hash”“pass”“pipe”“purge”“synth”“use return(hash)”for varnish 4tried,但不起作用,我认为问题不是由静态资源引起的,因为动态内容返回为空,请求肯定已到达后端,但不知怎的在nginx或清漆中丢失了。如果我绕过nginx,只使用varnish,它会像前面提到的那样工作,我不确定这是否与您当前的问题有关,但在我看来,如果您想缓存静态资源,您仍然希望在VCL中使用“hash”而不是“pipe”。