conditionally disable keepalives

Ryan Malayter malayter at
Fri Sep 17 22:36:42 MSD 2010

On Fri, Sep 17, 2010 at 12:20 PM, Ryan Malayter <malayter at> wrote:
> On Fri, Sep 17, 2010 at 11:34 AM, Cliff Wells <cliff at> wrote:
>> Or you could run a second Nginx instance between them and the main Nginx
>> instance.
> I thought about that... I suppose I could even have the same nginx
> instance proxy to itself, as the source IP would change to localhost
> on the subrequest, but it seems wasteful and potentially brittle.

So, the "proxy back to another nginx" (in this case the same instance)
Cliff suggested seems to be working, and I get a "Connection: close"
header for the IPs I am interested in, and keepalives seem to be off.

However, I do not get see the header I add in my special location,
even though I know it is hitting that location via rewrite. Is
proxy_pass treated specially by nginx somehow? I
would also expect to see two entries in the log files for every
request, but I do not.

Here is what I have (streamlined config)

server {

  if ($remote_addr ~ "^(111\.111\.111\.111|222\.222\.222\.222)$") {
    rewrite ^(.*)$ /nokeepalive$1;

  location /
  #and and many other locations

  location /nokeepalive {
    keepalive_timeout 0;
    add_header "X-NoKeepalive-Proxy" "true";
    proxy_set_header Host $host;
    #proxy back to myself at original request URI
    rewrite /nokeepalive(.*)$ $1;


More information about the nginx mailing list