Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've set up NGINX to return custom error documents for my proxied server, it shows the correct file but always returns a 200 OK header.

The relevant NGINX config is

server {

    proxy_intercept_errors on;

    location / {
        proxy_pass http://rmgshort/;

    error_page 404 = /error/404.html;
error_page 500 501 502 503 503 = /error/500.html;

    location /error/ {
        root /var/rmg/;

You can test this if you want, this page should return a 404 error, it returns the correct document but changes the status code to '200 OK' (Test HTTP headers here), if I replace root /var/rmg/ with internal; the correct header is returned but then my custom error page doesn't work.

How do I get NGINX to return my custom error document with the correct status header?

I'm running NGINX 1.0.4 on RHEL 6.1

share|improve this question
RedHat 6.0, or RHEL 6.0? – womble Jul 30 '11 at 12:18
@womble RHEL 6.1, sorry I just always refer to it as RedHat =) – Smudge Jul 30 '11 at 12:19
@womble Also not sure why I put 6.0 in the question #facepalm – Smudge Jul 30 '11 at 12:20
I don't think it actually matters here. – rvs Jul 30 '11 at 12:59
up vote 10 down vote accepted

Drop the = out of the error_page directive; you can specify any return code you like with =NNN (eg =401), but if you give a bare = it means "use the error code of the error handler", which for a static file will always be "200 OK". Without any =, you'll get the original error code returned.

Irritatingly, a straightforward reading of the (otherwise) fine manual (as at the time of writing this answer, anyway) might make you think that it's the other way around (= keeps the original return code), but local testing indicates that it definitely works the way I've described above.

share|improve this answer
This is not completely accurate. A bare = means that Nginx will use the returned status code of the designated error handler. Meaning if you do error_page 404 = /handler.phpand your handler.php script returns 200 then it uses 200, if handler.php returns 409 then it uses 409. I agree, though, that the wiki entry is worded poorly and I'll try to clarify it a bit. – Martin Fjordvald Jul 30 '11 at 12:52
@Martin: Thanks for the clarification; I've never actually used a non-static error handler (and obviously a non-existent error handler's pointless), so I'd never come across a situation where the return code would be non-200. I've updated my answer accordingly. – womble Jul 30 '11 at 12:53

Your Answer


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.