How to configure a 404 error page in NGINX

Source: Internet
Author: User

1. Create the secret 404.html page

2. Change nginx. conf and add fastcgi_intercept_errors on in the http definition area;

3. Change nginx. conf (or a separate website configuration file, for example, the site configuration file under nginx-> sites-enabled)

Add: error_page 404 =/404.html or error_page 404 = http://www.xxx.com/404.html in the server Region

4. Restart nginx after modification to test the correctness of nginx. conf:/opt/nginx/sbin/nginx-t

#502 and other errors can be configured in the same way.

Error_page 500 502 503 504 =/50x.html;

Note:

1. You must add: fastcgi_intercept_errors on. If this token is not set, creating 404.html and configuring error_page does not work. Fastcgi_intercept_errors Syntax: fastcgi_intercept_errors on | off default: fastcgi_intercept_errors off add location: http, server, location by default, nginx does not support custom 404 error page, only this command is set to on, nginx supports 404 error redirection. Note that if fastcgi_intercept_errors on is set, nginx will redirect the 404 error. In nginx, the precondition for 404 error redirection to take effect is that fastcgi_intercept_errors on is set, and the error_page option is set correctly (including syntax and corresponding 404 page)

2. Do not set the homepage as the 404 error page for the purpose of saving time or increasing the homepage weight, or use other methods to jump to the homepage.

3. The custom 404 page must be larger than 512 bytes; otherwise, the default 404 page of IE may appear. For example, the parameter is set to 404.html and the size is only 11 bytes (the content is 404 error ).

This article is from the blog "learning is everlasting ".

Supplement:

1.Create a 404.html page and store it in the root directory of the website.
2.Change nginx. conf and add fastcgi_intercept_errors on in the http definition area;
3.Change nginx. conf and add: error_page 404 =/404.html in the server area in the website configuration; or error_page 404 = http://www.jb51.net/404.html;
4.Verify nginx. conf:/usr/local/nginx/sbin/nginx-t
5.Restart nginx to take effect:/usr/local/nginx/sbin/nginx-s reload

502 and other errors can be configured in the same way.

Error_page 500 502 503 504 =/502.html;

However, I did not add fastcgi_intercept_errors on in the test. It can also be used normally, and the 404 page can also appear. Please try again.

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.