Method sharing for configuring 404 error pages under NGINX

  • 2020-05-06 12:17:39
  • OfStack

1. Create your own 404.html page,

2. Change nginx.conf in http definition area: fastcgi_intercept_errors on;

3. Change nginx.conf (or a separate website profile, for example in nginx->) Site profile under sites-enabled)

In the region of the server add: error_page = 404/404. html or error_page 404 = http:. / / www xxx. com / 404. html

4. Changes after the restart nginx, test nginx. Validity: conf/opt nginx sbin/nginx � t

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

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

notes:

1. Must add: fastcgi_intercept_errors on; If this option is not set, even creating 404.html and configuring error_page will not work. fastcgi_intercept_errors syntax: fastcgi_intercept_errors The important thing to note here is that it does not mean that if fastcgi_intercept_errors on is set, nginx will redirect the 404 error. The 404 error redirect takes effect in nginx only if fastcgi_intercept_errors on is set and error_page is correctly set (including syntax and corresponding 404 pages)

2. Do not specify the home page as a 404 error page for the purpose of saving trouble or improving the weight of the home page, and do not jump to the home page in other ways.

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

This is from

Supplement:

1. create your own 404.html page and place it in the root directory
2. changes nginx.conf is added in the http definition area:   fastcgi_intercept_errors   on;  
3. changes nginx.conf   in the site configuration adds server   area:   error_    404   =   / 400.html;   or   error_page     =   / 404 / www jb51. net / 404. html;
4 test nginx. conf correctness:  /usr/local/nginx sbin/nginx   � t
5. restart nginx effect:  /usr/local/nginx sbin/nginx   - s   reload

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

error_page     500   502   503   504   =   /502.html;  

But I didn't add   fastcgi_intercept_errors   on;     also works, also can appear 404 page, everybody also try.


Related articles: