404 - nginx configuration 40 page
给我你的怀抱
给我你的怀抱 2017-05-16 17:20:45
0
1
845
  1. What is a 404 page

    如果碰巧网站出了问题,或者用户试图访问一个并不存在的页面时,此时服务器会返回代码为404的错误信息,此时对应页面就是404页面。404页面的默认内容和具体的服务器有关。如果后台用的是NGINX服务器,那么404页面的内容则为:404 Not Found 
    
  2. Why you need to customize the 404 page

    在访问时遇到上面这样的404错误页面,我想99%(未经调查,估计数据)的用户会把页面关掉,用户就这样悄悄的流失了。如果此时能有一个漂亮的页面能够引导用户去他想去的地方必然可以留住用户。因此,每一个网站都应该自定义自己的404页面。
    
  3. How to customize the 404 page under NGINX

1.创建自己的404.html页面 
2.更改nginx.conf在http定义区域加入: fastcgi_intercept_errors on; 
3.更改nginx.conf(或单独网站配置文件,例如在nginx -> sites-enabled下的站点配置文件 )中在server 区域加入: error_page 404  /404.html  或者 error_page 404 =http://www.xxx.com/404.html
4.更改后重启nginx,,测试nginx.conf正确性: /opt/nginx/sbin/nginx –t 
#502 等错误可以用同样的方法来配置:error_page  500 502 503 504  /50x.html; 

Precautions:

1. Must add: 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页面) 

2. The custom 404 page must be larger than 512 bytes, otherwise the IE default 404 page may appear. For example, assume that 404.html is customized and the size is only 11 bytes (content: 404 error)

给我你的怀抱
给我你的怀抱

reply all(1)
我想大声告诉你

What are you doing?

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!