Change the status code that Nginx returns when a busy upstream unicorn is busy

I use Nginx in front of a unicorn. When the application is under heavy load and all unicorn workers are busy, nginx will return a 502 response that says the gateway is not configured correctly. I am fine with this behavior, but in this state I want nginx to return a 503 response code (server busy, please try again later), which is a much more suitable answer.

I saw this answer: Is it possible to change the HTTP status code returned when the proxy_pass gateway is in nginx?

which describes how to rewrite some status codes returned from the above proxy:

location / {
    proxy_pass http://backend;
    proxy_intercept_errors on;
    error_page 502 503 504 =503 @proxyisdown; # always reply with 503
}

location @proxyisdown {
    add_header Retry-After 500;
    index my_pretty_error_page.html; 
}

But there are two problems with this:

  • 502 ,
  • , - , , nginx (tcp?), nginx .

- , nginx , 503 502?

+5
1

? , backend, , 503. 503, , Nginx 502, backend .

0

All Articles