# Fastcgi\_keep\_conn consuming ports?

**URL:** <https://www.ruby-forum.com/t/fastcgi-keep-conn-consuming-ports/215539>\
**Category:** NGINX\
**Created:** [January 7, 2012, 4:35pm UTC](https://www.ruby-forum.com/t/fastcgi-keep-conn-consuming-ports/215539 "2012-01-07T16:35:45Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [January 7, 2012, 4:35pm UTC](https://www.ruby-forum.com/t/fastcgi-keep-conn-consuming-ports/215539/1 "2012-01-07T16:35:45Z")

</div>

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)

-Scott

---

<div class="post-metadata">

**Author:** ![Scott\_Conger](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/898d66/32.png) [@Scott\_Conger](https://www.ruby-forum.com/u/Scott_Conger)\
**Post date:** [January 7, 2012, 9:32pm UTC](https://www.ruby-forum.com/t/fastcgi-keep-conn-consuming-ports/215539/2 "2012-01-07T21:32:49Z")

</div>

Hello!

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

> 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 D.

---

<div class="post-metadata">

**Author:** ![Scott\_Conger](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/898d66/32.png) [@Scott\_Conger](https://www.ruby-forum.com/u/Scott_Conger)\
**Post date:** [January 8, 2012, 12:08am UTC](https://www.ruby-forum.com/t/fastcgi-keep-conn-consuming-ports/215539/3 "2012-01-08T00:08:31Z")

</div>

Hello Maxim,

Is there any place where both directives are well documented? I tried  
wiki and the new [nginx documentation](http://nginx.org/en/docs/), but no luck so far…

Appreciated!

Andrejs

Posted at Nginx Forum:

> **[Re: fastcgi\_keep\_conn consuming ports?](https://forum.nginx.org/read.php?2,220911,220923#msg-220923)**
>
> 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...

---

<div class="post-metadata">

**Author:** ![Scott\_Conger](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/898d66/32.png) [@Scott\_Conger](https://www.ruby-forum.com/u/Scott_Conger)\
**Post date:** [January 8, 2012, 1:04am UTC](https://www.ruby-forum.com/t/fastcgi-keep-conn-consuming-ports/215539/4 "2012-01-08T01:04:02Z")

</div>

Hello!

On Sat, Jan 07, 2012 at 06:08:09PM -0500, locojohn wrote:

> Hello Maxim,
> 
> Is there any place where both directives are well documented? I tried  
> wiki and the new [nginx documentation](http://nginx.org/en/docs/), but no luck so far..

Official documentation is expected to appear soon on [nginx.org](http://nginx.org).

Maxim D.

---

<div class="post-metadata">

**Author:** ![Scott\_Conger](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/898d66/32.png) [@Scott\_Conger](https://www.ruby-forum.com/u/Scott_Conger)\
**Post date:** [January 13, 2012, 8:44pm UTC](https://www.ruby-forum.com/t/fastcgi-keep-conn-consuming-ports/215539/5 "2012-01-13T20:44:10Z")

</div>

On Jan 8, 2012, at 4:03 AM, Maxim D. wrote:

> Maxim D.

It’s now here (done by Ruslan E.)

> **[Module ngx\_http\_upstream\_module](http://nginx.org/en/docs/http/ngx_http_upstream_module.html#keepalive)**
>
> The ngx\_http\_upstream\_module module is used to define groups of servers that can be referenced by the proxy\_pass, fastcgi\_pass, uwsgi\_pass, scgi\_pass, memcached\_pass, and grpc\_pass directives.

> **[Module ngx\_http\_proxy\_module](http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_http_version)**
>
> The ngx\_http\_proxy\_module module allows passing requests to another server.

> **[Module ngx\_http\_fastcgi\_module](http://nginx.org/en/docs/http/ngx_http_fastcgi_module.html#fastcgi_keep_conn)**
>
> The ngx\_http\_fastcgi\_module module allows passing requests to a FastCGI server.

---

<div class="post-metadata">

**Author:** ![Scott\_Conger](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/898d66/32.png) [@Scott\_Conger](https://www.ruby-forum.com/u/Scott_Conger)\
**Post date:** [January 14, 2012, 1:14am UTC](https://www.ruby-forum.com/t/fastcgi-keep-conn-consuming-ports/215539/6 "2012-01-14T01:14:00Z")

</div>

Thank you Andrew!

Andrejs

Posted at Nginx Forum:

> **[Re: fastcgi\_keep\_conn consuming ports?](https://forum.nginx.org/read.php?2,220911,221222#msg-221222)**
>
> 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...
