Nginx the method of configuring 404 error pages to share _nginx

Source: Internet
Author: User
1. Create your own 404.html page

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

3. Change nginx.conf (or a separate Web site profile, such as a site profile under Nginx-> sites-enabled)

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

4. Restart Nginx After the change, test nginx.conf correctness:/opt/nginx/sbin/nginx–t

Errors such as #502 can be configured in the same way.

Error_page 502 503 504 =/50x.html;

Precautions :

1. You must add: fastcgi_intercept_errors on; If this option is not set, even if the 404.html is created and the Error_page is configured, there is no effect. 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 pages, and only this instruction is set to On,nginx to support the redirection of 404 errors. It is important to note that the Fastcgi_intercept_errors On,nginx is not set to redirect the 404 error. In Nginx, the 404 error Redirection takes effect on the premise that fastcgi_intercept_errors on is set and the Error_page option (including syntax and corresponding 404 pages) is set correctly.

2. Do not for the sake of convenience or improve the weight of the home page to specify the first page as 404 error pages, and do not use other methods to jump to the home page.

3. A custom 404 page must be greater than 512 bytes, otherwise the IE default 404 page may appear. For example, imagine a custom 404.html with a size of 11 bytes (content: 404 error).

This article comes from the "learning to be eternal" blog

Add:

1. Create your own 404.html page and place it in the root directory of your site
2. change nginx.conf in the HTTP definition area add: fastcgi_intercept_errors on;
3. change nginx.conf in the Web site configuration in the server area: error_page 404 =/404.html; or error_page 404 = Http://www.jb51.net/4 04.html;
4. Test nginx.conf correctness: /usr/local/nginx/sbin/nginx–t
5. Restart Nginx entry into force: /usr/local/nginx/sbin/nginx-s Reload

502 errors can be configured in the same way.

Error_page 502 503 504 =/502.html;

But I am in the test I do not add fastcgi_intercept_errors on; Also can normal use, also can appear 404 pages, we also try it.

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.