Nginx Custom 404 Error Page Setup method

Source: Internet
Author: User

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

To see my nginx configuration:

Nginx.conf

The code is as follows

server {

...

Error_page 404 =/404.php;

...

}

At first glance there is nothing, the Internet search for a moment to know more than an equal sign!!! Instead of this:

Nginx.conf

The code is as follows

server {

...

Error_page 404/404.php;

...

}

Add other status code definition methods

Change nginx.conf joins in the HTTP definition area: fastcgi_intercept_errors on;

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 to work with multiple error codes

The code is as follows

Location/my_blog {

Error_page 502 503 504 =/server_error.html

}

Redirect to a completely different server, assuming you have an upstream server defined in the HTTP zone server2:

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 Nginx front-end +apache back-end server architecture.

Test configuration

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

Restart Nginx without error.

/etc/init.d/nginx restart

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.