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.

3
  • 1
    Check varnish logs for those requests. Also, why nginx in front of Varnish? Jan 14, 2016 at 10:32
  • Nginx for ssl http2. varnishlog don't shows this requests Jan 14, 2016 at 11:01
  • Check if varnishd wasn't it killing the child process while processing this URL.
    – karatedog
    Apr 17, 2016 at 20:21

1 Answer 1

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.

1
  • I'm unsure but why do you do double caching? nginx can cache, vanish do the same?
    – djdomi
    Jun 6, 2021 at 12:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .