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 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 ^ http://www.example.com/404.html? 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
Location: http://www.example.com/404.html

Any idea ?

share|improve this question

2 Answers 2

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

I finally did it like this :

error_page 404 http://www.example.com/404.html

It gives a 302 code and just works

share|improve this answer

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.