Nginx Custom 404 Error page

Source: Internet
Author: User

Configure custom 404 error page Steering in Nginx environment to avoid displaying blunt, unfriendly error messages to users. You can give the following hint: Sorry, the page you visited does not exist or has been deleted.


Precautions:


① first create a 404 error when the page appears, such as placed in the root directory of your site 404.html. (Free content)

② Add fastcgi_intercept_errors on to the HTTP zone in nginx.conf:

HTTP {

...

Fastcgi_intercept_errors on; #支持自定义4xx, 5xx pages

...
}

③ in the server area of nginx.conf (if the Web site has a separate profile, you need to include it in the server area of its configuration file) to add Error_page 404:

Situation one: The Global 404 page Jumps

Server

{

...

Error_page 404 = 404.html; #全局跳转

or error_page 404 = http://www.xxx.com/xxx/404.html;   # the difference between the absolute path and the relative path.

}

Scenario Two: 404 page jump For one of the paths of the server

location/news/{#只会在访问此路径时才会跳转
alias/happyface/hf_channel/;
Error_page 404 = 404.html; #此时404. html placed under/happyface/hf_channel/
}

Note: The status code returned at this time is 200, if you want to return a status code of 404, then "=" should be removed.

If you want to customize other errors, similarly:error_page 502 503 504 =/50x.html;

④ restart Nginx after saving.

/happyface/tengine/sbin/nginx-c Conf/nginx.conf-s Reload


This article is from the "Nobody Knows" blog, please be sure to keep this source http://cuixuemei.blog.51cto.com/8852728/1683006

Nginx Custom 404 Error page

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.