fastcgi_keep_conn consuming ports?

Maxim Dounin mdounin at mdounin.ru
Sat Jan 7 20:32:08 UTC 2012


Hello!

On Fri, Jan 06, 2012 at 03:02:54PM -0800, Scott Conger wrote:

> I wanted to try the new "fastcgi_keep_conn on;" configuration 
> setting. I grabbed 1.1.13 and added the setting to my 
> configuration. It seems to function, but I started getting HTTP 
> 502 errors when I put load on the server. Looking at netstat, it 
> seems to be consuming all available ports:
> 
> netstat -nt > stat.txt
> grep TIME_WAIT stat.txt | wc -l
> 49894
> 
> Everything works fine if I comment the configuration line out, 
> which leaves me a bit puzzled as to what is going on. Is there 
> perhaps some other setting I should be changing?
> 
> nginx -V
> nginx version: nginx/1.1.13
> built by gcc 4.1.2 20080704 (Red Hat 4.1.2-50)

If you want to use persistent fastcgi connections, you should use 
fastcgi_keep_conn *and* keepalive directive in the upstream block, 
i.e.

    upstream backend {
        server ...;
        keepalive 5;
    }

    server {
        ...

        location / {
            fastcgi_pass backend;
            fastcgi_keep_conn on;
            ...
        }
    }

Using fastcgi_keep_conn by itself only moves responsibility of 
closing fastcgi connections from backend to nginx, and thus moves 
TIME_WAIT connections from backend(s) to nginx side as well.

Maxim Dounin



More information about the nginx mailing list