I have an nginx setup which works very well. I am using an upstream block to load balance between two servers. These servers give HTTP 200 response even if they unable to serve the request, but they set custom http header like this:

X-Response-Status: Failed

When the response is OK, they give:

X-Response-Status: OK

Is it possible to configure nginx to try next upstream server while the first one gives "X-Response-Status: Failed"?

I mean like following in nginx config:

proxy_next_upstream error timeout http_* ($sent_http_x_response_status="Failed")



I have to keep upstream servers giving HTTP 200 even on errors because there is an error message in http body in binary form.

I have to pass this binary error to client if none of upstream server are able to serve the request.


There's no option for proxy_next_upstream to implement the behavior you describe.

Your application should not return an HTTP 200 if it couldn't actually process the request. Have the application return a more appropriate error, such as 500 or 503.

| improve this answer | |
  • The application could process the request, but it gives error message in the body in binary form (another protocol embeded to http) If the respond HTTP 500 the clients would not process message body. – ZsZs Mar 15 '13 at 14:58
  • If the client is meant to receive the error message, then you shouldn't be attempting to proxy to the next upstream! – Michael Hampton Mar 15 '13 at 14:59
  • The client should get the error message if none of the upstream servers are able to serve the request. – ZsZs Mar 15 '13 at 15:15
  • @ZsZs Non-200 responses may still contain response bodies with the error message. – mgorven Mar 15 '13 at 17:18
  • Thanks for your comment. You are right, but clients (typically browsers) does not show these bodies but want to parse as for example OCSP responses. When a browser sends an OCSP request and get a non HTTP 200 response it does not try to parse the response body. – ZsZs Mar 16 '13 at 14:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.