Nginx Configuration error_page 404 error page

Source: Internet
Author: User
Tags nginx server

Origin of the problem

Yesterday, a netizen in segmentfault.com asked, unable to do 404 redirect

Open the other side of the site casually entered a wrong address found 404 code, but the page is completely blank, and does not show the 404 page setting content

At that time to understand what the situation, as long as the nginx.conf configuration file to add a sentence fastcgi_intercept_errors on, you can

If not, whether it is error_page or nginx 404 jump can not be displayed normally (access to a nonexistent PHP page may display "no input file specified.") )

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

How to customize 404 pages under Nginx

1. change nginx.conf to add in the HTTP definition area: proxy_intercept_errors or fastcgi_intercept_errors

2, change nginx.conf, join in Server zone: Error_page 404  /404.html  or error_ Page 404 =http://www.xxx.com/404.html

3, after the change to restart Nginx, test nginx.conf correctness

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

Error_page 502 503 504/50x.html;

Error_page 501 502 503 504 @errpage; location @errpage {access_log logs/access.log maintry;proxy_pass URL;}

Precautions:

1. To add: fastcgi_intercept_errors on or proxy_intercept_errors

Default: Fastcgi_intercept_errors off

Add locations: HTTP, server, location

By default, Nginx does not support custom 404 error pages, only this directive is set to On,nginx to support 404 error redirection

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 error_page 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.