NGINX Configuration 404 Error page turn

Source: Internet
Author: User
Tags nginx server

What is 404 page

If something happens to the site, or if the user tries to access a page that does not exist, the server returns an error message with a code of 404, and the corresponding page is 404 pages. 404 The default content of the page is related to the specific server. If the background is using Nginx server, then the content of 404 pages is: 404 Not Found

Why customize 404 pages

When I visited the above 404 error page, I think 99% (without investigation, estimate data) users will turn off the page, the user so quietly lost. If you can have a beautiful page at this time to guide the user to the place where he wants to go must be able to retain users. Therefore, each site should customize its own 404 pages.

How to customize 404 pages under Nginx

IIS and Apache under the custom 404 page Experience Introduction article has been very much, Nginx is still relatively few, in order to solve their own problems specifically to this in-depth study. The results show that it is possible to configure a custom 404 page in Nginx, and it is very simple, just the following steps:

1.Create your own 404.html page

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

3.Change nginx.conf (or separate site profile, for example, in NginxSite configuration file under sites-enabled)

In the server zone join:Error_page 404/404.html orError_page 404 =http://www.xxx.com/404.html

4.Restart Nginx after 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. Must be added: Fastcgi_intercept_errors on; If this option is not set, there is no effect even if 404.html is created and Error_page is configured. 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 404 error redirection. It is important to note that it is not said that setting the Fastcgi_intercept_errors On,nginx will redirect the 404 error. In Nginx, 404 error redirection takes effect if fastcgi_intercept_errors on is set and the Error_page option is set correctly (including syntax and corresponding 404 pages)

2. Do not for the sake of convenience or improve the purpose of home page weight to designate the homepage as 404 error page, do not use other methods to jump to the homepage.

3. The custom 404 page must be greater than 512 bytes, otherwise the IE default 404 page may appear. For example, suppose you have customized 404.html with a size of only 11 bytes (content: 404 error)

NGINX Configuration 404 Error page turn

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.