Reputation: 119
In any response served by NGINX, how can one remove the "Connection: keep-alive" header?
We serve 100B+/month of sub 100-byte responses to under 10 clients from NGINX for RTB based ad serving. We're attempting to minimize the overhead (data size) to save on bandwidth costs. We do not want to actually have NGINX close the connection, only remove it from the header. The client is not a browser and will leave the connection open as per the HTTP/1.1 spec.
We have successfully removed the default response headers from our "no operation" response (204) using HttpHeadersMoreModule. It looks like this:
HTTP/1.1 204 No Content
Connection: keep-alive
We want to remove the other header so it looks like this:
HTTP/1.1 204 No Content
Our keepalive_timeout is set without a second value. As per NGINX HttpCoreModule documentation, without this [second] parameter, nginx does not send a Keep-Alive header. Out setting is:
keepalive_timeout 60s;
We've tried using and setting both 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've also tried:
rewrite_by_lua '
ngx.req.clear_header("Connection")
';
And even the:
more_clear_headers 'Connection*';
But we still see the header. We send so many responses that the Connection header actually costs us like $200 dollars a month.
Any help is appreciated.
Related and helpful: Nginx and raw headers
Upvotes: 10
Views: 7309
Reputation: 504
I don't know if this works in your case, but I had the same issue and I fixed it using keepalive_requests:
location xxx {
keepalive_requests 1;
....
}
Upvotes: 2