一聚教程网:一个值得你收藏的教程网站

热门教程

Nginx配置404示例介绍

时间:2022-06-30 18:53:28 编辑:袖梨 来源:一聚教程网


因为自己使用的是nginx的web服务器程序,介绍一下怎么配置404.

步骤:

1.创建自己的404.html页面,并放于网站根目录

2.更改nginx.conf在http定义区域加入: fastcgi_intercept_errors on;

3.更改nginx.conf 在网站配置中在server 区域加入: error_page 404 = /404.html; 或者 error_page 404 = http://www.xxx.com/404.html;

4.测试nginx.conf正确性: /usr/local/nginx/sbin/nginx -t

5.重启nginx生效: /usr/local/nginx/sbin/nginx -s reload
  
#502 等错误可以用同样的方法来配置。

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


注意事项:

1.必须要添加:fastcgi_intercept_errors on; 如果这个选项没有设置,即使创建了404.html和配置了error_page也没有效果。fastcgi_intercept_errors 语法: fastcgi_intercept_errors on|off 默认: fastcgi_intercept_errors off 添加位置: http, server, location 默认情况下,nginx不支持自定义404错误页面,只有这个指令被设置为on,nginx才支持将404错误重定向。这里需要注意的是,并不是说设置了fastcgi_intercept_errors on,nginx就会将404错误重定向。在nginx中404错误重定向生效的前提是设置了fastcgi_intercept_errors on,并且正确的设置了error_page这个选项(包括语法和对应的404页面)

热门栏目