Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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 want nginx to handle 404 error status and redirect them to another domain.

In headers "Location:" is updated but status is still 404 but should be 301.

Here is my code :

# error handling
error_page 404 @404;
log_not_found off;
proxy_intercept_errors on;

and :

location @404 {
  rewrite ^ permanent;

So following command lynx -head -dump 'http://localhost:9999/a_404_error' gives me :

HTTP/1.1 404 Not Found
Server: nginx/0.8.54
Date: Mon, 11 Apr 2011 18:59:12 GMT
Content-Type: text/html
Content-Length: 169
Connection: close

Any idea ?

share|improve this question

I finally did it like this :

error_page 404

It gives a 302 code and just works

share|improve this answer

error_page 404 = @404 will allow location @404 to set the response status

share|improve this answer
I tried that but it didn't work – jney Apr 13 '11 at 10:40
You're sure you included the =, and you reloaded your config? I just tested it and it worked fine for me. – kolbyjack Apr 13 '11 at 12:19

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.