Nginx custom 404 error page setting method

  

Today suddenly found a problem, the site set a custom 404 page, showing no problem, just return the status code is 200, not 404! !

Go to my nginx configuration:

nginx.conf

The code is as follows server {

...

error_page 404 = /404.php;

...

}

At first glance, there is nothing wrong with it. After searching online, I know that there is an equal sign! ! ! Change to this:

nginx.conf

The code is as follows

server {

...

error_page 404 /404.php ;

...

}

Add other state code definition methods

Change nginx.conf in the http definition area to join: fastcgi_intercept_errors on;< Br>

Set a 404 page for the specified location

The code is as follows

location /my_blog { error_page 404 = /article_not_found.html; }

You can use a single Error page together to handle multiple error codes

Code is as follows

location /my_blog { error_page 500 502 503 504 = /server_error.html }

Redirect to a completely different The server, assuming you have an upstream server server2 defined in the http area:

The code is as follows

upstream server2 { server 10.0.0.1:80; } server { location /my_blog { error_page 404 = @ Try_server2; } location @try_server2 { proxy_pass http://server2; }

This feature can be used in the server architecture of the Nginx front end + Apache backend.

Test Configuration

/usr/local/nginx/sbin/nginx -t

Restart nginx without error [

/etc/init.d/Nginx restart

Copyright © Windows knowledge All Rights Reserved