加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 运营中心 > Nginx > 正文

Varnish前面的Nginx有时会产生“上游过早关闭连接,同时从上游读

发布时间:2020-12-13 21:12:41 所属栏目:Nginx 来源:网络整理
导读:我在同一台服务器上的Varnish(4.1.0)前面有Nginx(1.9.9). //nginxupstream 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 C

我在同一台服务器上的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,并确保返回(通过)适用于你的场景,但在大多数地方它可能是答案.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读