Nginx下配置404错误引导页面

MY进修之路 2012-07-06

在Nginx下,配置404等http状态码的引导页面其他很简单,注意以下几点就行。

1,创建自己的404页面,比如404.html或404.php。html和php都支持,但是必须确保页面的大小不能超过512字节,否则IE浏览器会用默认的错误页面。

2,更改nginx.conf配置文件,在http定义区域加入fastcgi_intercept_errors on;

3,在server区域加入error_page 404 = /404.html

4,测试nginx配置是否正确。

[root@CentOS conf]# /usr/local/webserver/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/webserver/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/webserver/nginx/conf/nginx.conf test is successful
[root@CentOS conf]#

5,平滑重启nginx。

[root@CentOS conf]# /usr/local/webserver/nginx/sbin/nginx -s reload

这时,在浏览器输入不存在的页面,就会显示404.html页面的内容。

定义其他http状态码的引导页面道理一样

相关推荐