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 nginx setup to pass to an upstream using proxy pass. The upstream is written to return a 502 http response on certain requests, rather then returning the 502 with all the header I would like nginx to recoginse this and return 444 so nothing is returned. Is this possible?

I also tried to return 444 on any 50x error but it doesn't work either.

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  /50x.html;
}

location = /50x.html {
    return 444;
}

error_page  404              /404.html;
location = /404.html {
    return 444;
}
share|improve this question

2 Answers 2

up vote 2 down vote accepted

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.

share|improve this answer
    
That did it, thanks very much. –  Mark Jun 29 '12 at 19:03

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;
share|improve this answer
    
Thanks for that, now I get the 444 for everything except when my upstream returns a 502, it just passes back normally to the client. –  Mark Jun 29 '12 at 19:00

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.