404错误是WWW网站访问容易出现的错误。最常见的出错提示:404 NOT FOUND。404错误页的设置对网站SEO有很大的影响,而设置不当,比如直接转跳主页等,会被搜索引擎降权拔毛。404页面的目的应该是告诉用户:你所请求的页面是不存在的,同时引导用户浏览网站其他页面而不是关掉窗口离去。搜索引擎通过HTTP状态码来识别网页的状态。当搜索引擎获得了一个错误链接时,网站应该返回404状态码,告诉搜索引擎放弃对该链接的索引。而如果返回200或302状态码,搜索引擎就会为该链接建立索引,这导致大量不同的链接指向了相同的网页内容。结果是,搜索引擎对网站的信任度大幅降低。 下面是LNMP设置Nginx 404错误页教程: 1、vi /usr/local/nginx/conf/nginx.conf 编辑Nginx配置文件,在http 区段添加下面代码: fastcgi_intercept_errors on; 2、编辑网站配置文件,比如本站:vi /usr/local/nginx/conf/vhost/onelone.com.conf ,在server 区段添加下面代码: error_page 404 = /404.html; 注意:有网友测试上行代码需要去掉等号才会返回正确的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 。 5、404错误页面制作的注意事项: 一、不要将404错误转向到网站主页,否则可能会导致主页在搜索引擎中被降权或消失 二、不要使用绝对URL,如果使用绝对URL返回的状态码是302+200,这样会产生大量的重复网页。 三、404页面设置完成,一定要检查是否正确。http头信息返回的一定要是404状态。这个可以通过服务器头部信息检查工具进行检查。 四、404页面不要自动跳转,让用户来决定去向。 五、自定义的404页面必须大于512字节,否则可能会出现IE默认的404页面。 转载自:http://www.onelone.com/tutorial/404error.html Loading... 404错误是WWW网站访问容易出现的错误。最常见的出错提示:404 NOT FOUND。404错误页的设置对网站SEO有很大的影响,而设置不当,比如直接转跳主页等,会被搜索引擎降权拔毛。404页面的目的应该是告诉用户:你所请求的页面是不存在的,同时引导用户浏览网站其他页面而不是关掉窗口离去。搜索引擎通过HTTP状态码来识别网页的状态。当搜索引擎获得了一个错误链接时,网站应该返回404状态码,告诉搜索引擎放弃对该链接的索引。而如果返回200或302状态码,搜索引擎就会为该链接建立索引,这导致大量不同的链接指向了相同的网页内容。结果是,搜索引擎对网站的信任度大幅降低。<!--more--> 下面是LNMP设置Nginx 404错误页教程: 1、vi /usr/local/nginx/conf/nginx.conf 编辑Nginx配置文件,在http 区段添加下面代码: <code>fastcgi_intercept_errors on;</code> <span class="external-link"><a class="no-external-link" href="http://www.xiaoten.com/usr/uploads/2013/05/982238926.jpg" target="_blank"><i data-feather="external-link"></i><img class="attachment-full size-full" src="http://www.xiaoten.com/usr/uploads/2013/05/982238926.jpg" sizes="(max-width: 499px) 100vw, 499px" srcset="http://www.xiaoten.com/usr/uploads/2013/05/982238926-300x236.jpg 300w, http://www.xiaoten.com/usr/uploads/2013/05/982238926.jpg 499w" alt="982238926" width="499" height="393" style=""></a></span> 2、编辑网站配置文件,比如本站:vi /usr/local/nginx/conf/vhost/onelone.com.conf ,在server 区段添加下面代码: <code>error_page 404 = /404.html;</code> <span style="color: #ff0000;">注意:有网友测试上行代码需要去掉等号才会返回正确的404状态,所以请同学们自行测试是否要去掉等号。</span> <span class="external-link"><a class="no-external-link" href="http://www.xiaoten.com/usr/uploads/2013/05/1026201641.jpg" target="_blank"><i data-feather="external-link"></i><img class="attachment-full size-full" src="http://www.xiaoten.com/usr/uploads/2013/05/1026201641.jpg" sizes="(max-width: 639px) 100vw, 639px" srcset="http://www.xiaoten.com/usr/uploads/2013/05/1026201641-300x168.jpg 300w, http://www.xiaoten.com/usr/uploads/2013/05/1026201641-520x292.jpg 520w, http://www.xiaoten.com/usr/uploads/2013/05/1026201641-720x404.jpg 720w, http://www.xiaoten.com/usr/uploads/2013/05/1026201641.jpg 639w" alt="1026201641" width="639" height="358" style=""></a></span> 3、测试配置文件是否正确:/usr/local/nginx/sbin/nginx -t ,返回下面代码通过: <code>the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok configuration file /usr/local/nginx/conf/nginx.conf test is successful</code> 4、重启LNMP生效:/root/lnmp restart 。 <span class="external-link"><a class="no-external-link" href="http://www.xiaoten.com/usr/uploads/2013/05/3695260941.jpg" target="_blank"><i data-feather="external-link"></i><img class="attachment-full size-full" src="http://www.xiaoten.com/usr/uploads/2013/05/3695260941.jpg" sizes="(max-width: 661px) 100vw, 661px" srcset="http://www.xiaoten.com/usr/uploads/2013/05/3695260941-300x197.jpg 300w, http://www.xiaoten.com/usr/uploads/2013/05/3695260941.jpg 661w" alt="3695260941" width="661" height="433" style=""></a></span> 5、404错误页面制作的注意事项: 一、不要将404错误转向到网站主页,否则可能会导致主页在搜索引擎中被降权或消失 二、不要使用绝对URL,如果使用绝对URL返回的状态码是302+200,这样会产生大量的重复网页。 三、404页面设置完成,一定要检查是否正确。http头信息返回的一定要是404状态。这个可以通过服务器头部信息检查工具进行检查。 四、404页面不要自动跳转,让用户来决定去向。 五、自定义的404页面必须大于512字节,否则可能会出现IE默认的404页面。 转载自:<span class="external-link"><a class="no-external-link" href="http://www.onelone.com/tutorial/404error.html" target="_blank"><i data-feather="external-link"></i>http://www.onelone.com/tutorial/404error.html</a></span> © 允许规范转载 赞 如果觉得我的文章对你有用,请随意赞赏
2 条评论
我记得error_page 404 = /404.html;应该是error_page 404 /404.html;没有等于号的
@twd2: ……我一直用的都是带等号的那个…………