nginx crash

Maxim Dounin mdounin at mdounin.ru
Sun Nov 13 23:54:55 UTC 2011


Hello!

On Sun, Nov 13, 2011 at 11:16:56PM +0000, António P. P. Almeida wrote:

> 
> On 12 Nov 2011 14h07 WET, magicbearmo at gmail.com wrote:
> 
> > happen on a of main upstream server dead.
> >
> > Here is the config
> >
> > proxy_cache_path /dev/shm/cdn_cache_comment levels=1:2
> > keys_zone=cache_comment_mem:32m max_size=128m; limit_req_zone
> > $binary_remote_addr zone=limit_comment:16m rate=50r/s;
> >
> > upstream backend_comment {
> > 	server 10.0.0.1 weight=10 fail_timeout=30s;
> > 	server 10.0.0.2 backup weight=5 fail_timeout=30s;
> > 	keepalive 30;
>         ^^^^^^^^^^^^^
> I believe you have to use:
> 
> proxy_http_version 1.1;
> 
> in the location that invoke this upstream for getting keep alive to
> the backends. AFAIK this is undocumented and would be nice if Maxim
> can shed some light on this issue.

Keepalive connections are possible with HTTP/1.0 as well.  There 
are some problems with them though:

1. There is no standard which defines keepalive connections in 
HTTP/1.0.  It works with major web servers (including nginx), but 
may not work with others.

2. In HTTP/1.0 connection can't be kept alive if response 
Content-Length isn't known (as response end is signalled by 
connection close).

Due to the above reasons I would recommend using HTTP/1.1 to keep 
backend connections alive.  But it doesn't mean they aren't 
possible (and I'm quite sure MagicBear's config works as expected).

The required thing is

    proxy_set_header Connection "";

in case of HTTP/1.1, or

    proxy_set_header Connection "keep-alive";

in case of HTTP/1.0.

(Well, "Connection: keep-alive" will work in HTTP/1.1 case as 
well, actually.  But an empty string is enough.)

> Ditto for:
> 
> fastcgi_keep_conn on;
> 
> in the case of FCGI upstreams.

The fastcgi_keep_conn directive is required to keep connections 
alive with fastcgi upstreams.  It instructs nginx to claim 
responsibility of closing connection with appropriate flag in 
fastcgi protocol.  Without this directive connection will be 
closed by fastcgi application (upstream) and it won't be possible 
to keep it alive. 

Maxim Dounin



More information about the nginx-devel mailing list