Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

nginx and proxy_pass - send Connection: close headers

Tags:

http

nginx

nginx seems to be replacing the Connection: close header that upstream is sending, and replacing it with a Connection: keep-alive header. Is there any way I can override it?

http {
  upstream main {
    server 127.0.0.1:8000;
  }
  server {
    listen 443;
    ssl on;
    ssl_certificate server.crt;
    ssl_certificate_key server.key;
    location / {
      proxy_pass http://main;
    }
    location /find {
      proxy_pass http://main;
      proxy_buffering off;
    }
  }
}
like image 354
nornagon Avatar asked Feb 24 '11 06:02

nornagon


2 Answers

Setting keepalive_requests 0; convinced nginx to send Connection: close.

like image 85
nornagon Avatar answered Oct 17 '22 13:10

nornagon


The Connection header is specific to a connection.

From the HTTP/1.1 spec,

The Connection general-header field allows the sender to specify options that are desired for that particular connection and MUST NOT be communicated by proxies over further connections.

So what nginx sends is independent of what's being sent from upstream and must be. Here are some options:

keepalive_requests 0 works if you never want connections reused.

keepalive_disable ua works for a particular user agent.

And this answer works an ip.

like image 24
Nelson Page Avatar answered Oct 17 '22 14:10

Nelson Page