nginx环境自定义404页面

首先打开nginx.conf文件,在fastcgi_temp_file_write_size 128k; 下面添加
fastcgi_intercept_errors on;
注意,包括;号

然后在需要定义的站点的里面添加
error_page 404 = /404.htm;

例如
[gn_quote style=”1″]
server
{
listen 80;
server_name vps.imcat.in;
index index.html index.htm index.php;
error_page 404 = /404.htm;
include location.conf;
root /home/www/logs;
}
[/gn_quote]
[gn_accordion][spoiler]
404页面需要放在站点的跟目录下
[/spoiler][/gn_accordion]

测试配置
/usr/local/nginx/sbin/nginx -t

没错误就重启nginx
/root/lnmp restart

[gn_dropcap style=”1″ size=”2″]D
[/gn_dropcap]
[gn_quote style=”3″]
注意事项:
1.必须要添加:fastcgi_intercept_errors on; 如果这个选项没有设置,即使创建了404.html和配置了error_page也没有效果。
2.不要出于省事或者提高首页权重的目的将首页指定为404错误页面,也不要用其它方法跳转到首页。
3.自定义的404页面必须大于512字节,否则可能会出现IE默认的404页面。例如,假设自定义了404.html,大小只有11个字节(内容为:404错误)。
[/gn_quote]

《nginx环境自定义404页面》上有12条评论

回复 朋朋 取消回复

您的电子邮箱地址不会被公开。 必填项已用*标注