nginx error_page配置

网站有时候会出现页面不存在或者是其他的错误状态,用error_page,把403,404,503,504的错误跳转到错误的页面上,可以给用户更好的体验
配置
error_page 403 = http://www.lynn.cn/403.html;
error_page 404 = http://www.lynn.cn/404.html;
error_page 503 = http://www.lynn.cn/503.html;
error_page 504 = http://www.lynn.cn/504.html;
error_page可以使用的范围有http/server/location/if in location
配置好之后/etc/init.d/nginxd reload
测试,普通的静态文件不存在,能够返回到错误页面,但是php页面不行
google之,是因为fastcgi没有把错误给nginx,参考
http://bbs.linuxtone.org/thread-6848-1-1.html
 
还需要设置
fastcgi_intercept_errors on;
设置好之后,重新加载配置文件,测试,ok
 
fastcgi_intercept_errors
syntax: fastcgi_intercept_errors on|off
default: fastcgi_intercept_errors off
context: http, server, location
This directive determines whether or not to transfer 4xx and 5xx errors back to the client or to allow Nginx to answer with directive error_page.
Note: You need to explicitly define the error_page handler for this for it to be useful. As Igor says, "nginx does not intercept an error if there is no custom handler for it it does not show its default pages. This allows to intercept some errors, while passing others as are."


本文出自 “lynnteng0” 博客,转载请与作者联系!

你可能感兴趣的:(nginx,error_page, )