Nginx return 444 depending on upstream response code
Solution 1:
Yes, it is possible. As per the documentation of error_page, it could be done like this...
error_page 500 502 503 504 =444 /50x.html;
In the same way...
error_page 404 =444 /404.html;
So, your entire sample configuration would become...
location / { return 444; } location ^~ /service/v1/ { proxy_pass http://127.0.0.1:3333; proxy_next_upstream error timeout http_502; error_page 500 502 503 504 =444 /50x.html; } error_page 404 =444 /404.html;
Solution 2:
If the backend is actually returning a 502, and it's not being generated by nginx internally because the backend is unreachable, then you'll need to turn on proxy_intercept_errors for your error_page directive to take effect.