Nginx and proxy_pass - send connection: close headers

nginx seems to replace the header Connection: closethat the upstream sends, and replace it with the header Connection: keep-alive. Is it possible to 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;
    }
  }
}
+5
source share
5 answers

Setup keepalive_requests 0;convince nginx to send Connection: close.

+3
source

The connection header refers to the connection.

From the HTTP / 1.1 specification,

The Connection general header field allows the sender to specify the parameters that are required for this particular connection, and the proxy MUST NOT be transmitted through additional connections.

, nginx , , . :

keepalive_requests 0 , .

keepalive_disable ua .

ip.

+2

fastcgi_finish_request(), PHP-FPM PHP FastCGI:

php . , script, . , memcached , -. fastcgi_finish_request() - php, . - " " , php , , , ..

http://php-fpm.org/wiki/Features#fastcgi_finish_request.28.29

+1

Disabling keepalive on a secure server can increase the load on the server, check the HTTPS server optimization session in this document. http://nginx.org/en/docs/http/configuring_https_servers.html

I can set a small keepalive_requests value and set keepalive_requests also

0
source

You can plan NGINX. Take FastCGIfor example add

if (strcmp((char *)h->key.data, "Connection") == 0 && strcmp((char *)h->value.data, "close") == 0) {
     ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, "Set Connection: close");
     r->keepalive = 0;
}

in line src/http/modules/ngx_http_fastcgi_module.c1977, immediately after the header analyzer.

0
source

All Articles