Nginx and upstream HTTP/1.1

Unlike Squid, or the iPlanet/Sun proxy server 4.0, or Oracle’s Traffic Director, but quite like haproxy, nginx does not enable HTTP/1.1 persistent connections to upstream servers. Also, for good measure, there’s this set of hoops through which one must jump if one wishes to tamper with this default setting.

1. Switch upstream HTTP protocol to 1.1

proxy_http_version 1.1;

2. Make sure that nginx sends no Connection: close to upstream servers

proxy_set_header Connection "";

3. And finally, enable keepalive on the target upstream

upstream somehttp11server {
    server somehttp11server:8080;
    keepalive 128;

Miss one or more of this and one wouldn’t benefit from upstream persistent connections: there wouldn’t be a connection pool, or there would be a connection pool to which connections are not returned (because they get closed off  by upstreams; either due to them receiving HTTP/1.0 requests, or HTTP/1.1 ones carrying a Connection: close).

On a related note, nginx seems to offer no timeout settings for it’s upstream connection pool. Idle upstream connections lie around till an impatient upstream server times them out. Yet another deviation from other popular proxy agent software  – for example, check out Oracle Traffic Director’s http-client-config options.

I’m not really complaining (much, I guess) since I’m extremely impressed with nginx’s performance overall. Not so much with it’s code layout/style, but that’s another story for another day.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s