Remove the “Connection: save” response header in the NGINX 204 response with HTTP / 1.1

In any response served by NGINX, how can I remove the "Connection: keep-alive" header?

We serve 100B + / month responses for more than 100 bytes to 10 clients from NGINX for RTB-based advertising. We try to minimize overhead (data size) in order to save on bandwidth costs. We do not want NGINX to close the connection, removing it only from the header. The client is not a browser and will leave the connection open in accordance with the HTTP / 1.1 specification.

We have successfully removed the default response headers from our no-operation response (204) using the HttpHeadersMoreModule . It looks like this:

HTTP/1.1 204 No Content Connection: keep-alive 

We want to remove another header so that it looks like this:

 HTTP/1.1 204 No Content 

Our keepalive_timeout is set without a second value. According to the NGINX documentation, the HttpCoreModule without this [second] parameter, nginx does not send a Keep-Alive header. Output:

 keepalive_timeout 60s; 

We tried to use and install http://wiki.nginx.org/HttpHeadersMoreModule#more_clear_headers and http://wiki.nginx.org/HttpHeadersMoreModule#more_clear_input_headers :

 more_clear_headers 'Connection'; more_clear_input_headers 'Connection'; 

We also tried:

 rewrite_by_lua ' ngx.req.clear_header("Connection") '; 

And even:

 more_clear_headers 'Connection*'; 

But we still see the headline. We send so many responses that the Connection header really costs us $ 200 a month.

Any help is appreciated.

Related and useful: Nginx and source headers

+6
source share

All Articles