Forum: NGINX Changing Nginx keep-alive behavior based on error response of proxied server

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
nginxCoder (Guest)
on 2013-08-06 21:25
(Received via mailing list)
I was wondering if there is a way in Nginx to force a client to close
connection (or modify the keepalive parameters) when a proxied server
returns a particular error response. To elaborate a bit, if I have Nginx
a proxy in front of a backend server, can Nginx be made to change its
alive behavior based on the error response of the back end server? For
example, if I have keepalive_requests as, say 30, in my Nginx config but
the proxied server returns some 4xx or 5xx error, I'd like to send a
connection close to the client or perhaps make keepalive_requests as 0
that connection, forcing the client to open up a new connection.

One approach I tried was to intercept the error (proxy_intercept_errors
and used the error page directive to refer to a location wherein I set
keepalive_requests as 0. This seems to make the client close the current
connection but there doesn't seem to be a way to return the actual
from the backend server when using proxy_intercept_errors. It would be
to be able to return the actual error response from the backend server
just return some static content.
Please let me know if  anyone has any suggestions or ideas.

Posted at Nginx Forum:,241653,241653#msg-241653
nginxCoder (Guest)
on 2013-08-09 05:36
(Received via mailing list)
Any ideas/suggestions related to forcing a client connection close on
certain errors from proxied server? Please refer my previous post for

Posted at Nginx Forum:,241653,241721#msg-241721
This topic is locked and can not be replied to.