[b][color=red][b]非原创,来自:http://blog.sina.com.cn/s/blog_6e5bb2310101dwsj.html[/b][/color][/b]
LNMP设置Nginx 404错误页教程:
1、vi /usr/local/nginx/conf/nginx.conf 编辑Nginx配置文件,在http 区段添加下面代码:
fastcgi_intercept_errors on;
LNMP设置Nginx <wbr>404错误页教程[图解]
[img]http://dl2.iteye.com/upload/attachment/0111/1504/82bd5869-23ef-3590-a456-a0f6880bbe07.jpg[/img]
2、编辑网站配置文件,比如本站:vi /usr/local/nginx/conf/vhost/onelone.com.conf ,在server 区段添加下面代码:
error_page 404 = /404.html;
[img]http://dl2.iteye.com/upload/attachment/0111/1506/94a89f66-d27e-380f-84b2-f914e5fad297.jpg[/img]
注意:有网友测试上行代码需要去掉等号才会返回正确的404状态,所以请同学们自行测试是否要去掉等号。
LNMP设置Nginx <wbr>404错误页教程[图解]
3、测试配置文件是否正确:/usr/local/nginx/sbin/nginx -t ,返回下面代码通过:
the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok configuration file /usr/local/nginx/conf/nginx.conf test is successful
4、重启LNMP生效:/root/lnmp restart 。
LNMP设置Nginx <wbr>404错误页教程[图解]
[img]http://dl2.iteye.com/upload/attachment/0111/1508/16ecaee4-f56e-3b32-97db-638d2c770b60.jpg[/img]
5、404错误页面制作的注意事项:
一、不要将404错误转向到网站主页,否则可能会导致主页在搜索引擎中被降权或消失
二、不要使用绝对URL,如果使用绝对URL返回的状态码是302+200,这样会产生大量的重复网页。
三、404页面设置完成,一定要检查是否正确。http头信息返回的一定要是404状态。这个可以通过服务器头部信息检查工具进行检查。
四、404页面不要自动跳转,让用户来决定去向。
五、自定义的404页面必须大于512字节,否则可能会出现IE默认的404页面。
LNMP设置Nginx 404错误页教程:
1、vi /usr/local/nginx/conf/nginx.conf 编辑Nginx配置文件,在http 区段添加下面代码:
fastcgi_intercept_errors on;
LNMP设置Nginx <wbr>404错误页教程[图解]
[img]http://dl2.iteye.com/upload/attachment/0111/1504/82bd5869-23ef-3590-a456-a0f6880bbe07.jpg[/img]
2、编辑网站配置文件,比如本站:vi /usr/local/nginx/conf/vhost/onelone.com.conf ,在server 区段添加下面代码:
error_page 404 = /404.html;
[img]http://dl2.iteye.com/upload/attachment/0111/1506/94a89f66-d27e-380f-84b2-f914e5fad297.jpg[/img]
注意:有网友测试上行代码需要去掉等号才会返回正确的404状态,所以请同学们自行测试是否要去掉等号。
LNMP设置Nginx <wbr>404错误页教程[图解]
3、测试配置文件是否正确:/usr/local/nginx/sbin/nginx -t ,返回下面代码通过:
the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok configuration file /usr/local/nginx/conf/nginx.conf test is successful
4、重启LNMP生效:/root/lnmp restart 。
LNMP设置Nginx <wbr>404错误页教程[图解]
[img]http://dl2.iteye.com/upload/attachment/0111/1508/16ecaee4-f56e-3b32-97db-638d2c770b60.jpg[/img]
5、404错误页面制作的注意事项:
一、不要将404错误转向到网站主页,否则可能会导致主页在搜索引擎中被降权或消失
二、不要使用绝对URL,如果使用绝对URL返回的状态码是302+200,这样会产生大量的重复网页。
三、404页面设置完成,一定要检查是否正确。http头信息返回的一定要是404状态。这个可以通过服务器头部信息检查工具进行检查。
四、404页面不要自动跳转,让用户来决定去向。
五、自定义的404页面必须大于512字节,否则可能会出现IE默认的404页面。