5

I have Nginx(1.9.9) on front of Varnish(4.1.0) on the same server.

//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"

For 0.001% of requests nginx shows error:

[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"

Playing with proxy_buffers didn't help.

Xiong Chiamiov
  • 2,954
  • 2
  • 27
  • 30

1 Answers1

0

We had this very same issue, using Nginx for SSL and HTTP2, Varnish for caching and Apache for the actual web serving.

I noticed it was only happening on requests that we had set to bypass Varnish. For some reason, years ago, we used return(pipe) in our VCL file for those. I changed it from return(pipe) to return(pass) and, voilà, problem solved.

Obviously you'll need to look at your VCL and make sure that return(pass) works for your scenario, but in most places it likely will be the answer.