Upstrea/ Keepalive strange behaviour

Maxim Dounin mdounin at
Tue Dec 10 17:37:49 UTC 2013


On Mon, Dec 09, 2013 at 04:52:11PM +0000, David DONCHEZ wrote:

> Hello all,
> I have a strange behavior when using upstream/keepalive and it could be
> fine if someone can give me some feedback regarding this setup.
> I have multiple locations with proxy_pass directive, i use
> proxy_http_version 1.1 and "Connection" header is cleared. 
> In the upstream block, i have 2 or more upstream IP and i have add the
> directive keepalive.
> Now, sometimes i see this error log : "upstream prematurely closed
> connection while reading response header from upstream".
> A tcpdump show that nginx send a GET to his upstream but the TCP
> connection is closed and nginx don't  receive the response from
> upstream. Most of the time, nginx uses another upstream server and the
> transaction is successfully completed.
> This behavior appears with different upstream server.

As per HTTP specification, persistent connection can be closed by 
the server at any time, and clients should handle this.   That is, 
that's more or less normal, and nginx is expected to handle this 
fine by using another upstream server if this happens.

Maxim Dounin

More information about the nginx mailing list