Welcome! Log In Create A New Profile

Advanced

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

August 06, 2013 03:24PM
I was wondering if there is a way in Nginx to force a client to close the connection (or modify the keepalive parameters) when a proxied server returns a particular error response. To elaborate a bit, if I have Nginx as a proxy in front of a backend server, can Nginx be made to change its keep 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 if 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 for that connection, forcing the client to open up a new connection.

One approach I tried was to intercept the error (proxy_intercept_errors on) and used the error page directive to refer to a location wherein I set the 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 response from the backend server when using proxy_intercept_errors. It would be nice to be able to return the actual error response from the backend server than just return some static content.
Please let me know if anyone has any suggestions or ideas.
Thanks.
SubjectAuthorPosted

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

nginxCoderAugust 06, 2013 03:24PM

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

nginxCoderAugust 08, 2013 11:35PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 81
Record Number of Users: 7 on March 06, 2014
Record Number of Guests: 156 on March 20, 2014
Powered by nginx    Powered by FreeBSD    PHP Powered    Powered by Percona     ipv6 ready