Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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")

Thanks!

UPDATE1:

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.

share|improve this question
add comment

1 Answer

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.

share|improve this answer
    
Thanks for your quick reply! –  ZsZs Mar 15 '13 at 14:53
    
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
show 1 more comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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