我在同一台服务器上的Varnish(4.1.0)前面有Nginx(1.9.9).
//nginx
upstream varnish {
server 127.0.0.1:8391;
keepalive 16;
}
location ~ \.php${
proxy_pass http://varnish;
proxy_http_version 1.1; #for 1.0 varnish shows blank page
proxy_set_header Connection "";
proxy_redirect off;
proxy_set_header Host $host:$server_port;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_read_timeout 600;
proxy_send_timeout 600;
proxy_connect_timeout 600;
}
//varnish
DAEMON_OPTS="-a :8391 \
-T localhost:6082 \
-f /etc/varnish/default.vcl \
-S /etc/varnish/secret \
-s malloc,1024m"
对于0.001%的请求,nginx显示错误:
[error] 5331#5331: *7392847 upstream prematurely closed connection while reading response header from upstream,client: xx.xx.xx.xx,server: _,request: "GET /home HTTP/1.1",upstream: "http://127.0.0.1:8391/index.php?q=/home",host: "xxx",referrer: "xxx"
使用proxy_buffers没有帮助.
最佳答案
我们遇到了同样的问题,使用Nginx进行SSL和HTTP2,使用Varnish进行缓存,使用Apache进行实际的Web服务.
我注意到它只发生在我们设置绕过Varnish的请求上.出于某种原因,多年前,我们在VCL文件中使用了return(pipe).我把它从返回(管道)改为返回(通过),并且,问题解决了.
显然你需要查看你的VCL,并确保返回(通过)适用于你的场景,但在大多数地方它可能是答案.