nginx 设置错误的自定义404页面跳转到500
2014-06-06 16:01
756 查看
5年前写的站, 当时是在apache下写的error page, 换了nginx后, 404页面直接跳到了500 服务器内部错误.
只需要在配置
try_files 的时候指定一下就可以了
我的是debian, 在/etc/nginx/site-available/default 里面location /
server{
[plain] view
plaincopy
</pre><pre name="code" class="plain"> location / {
<span style="white-space:pre"> </span>try_files $uri $uri/ /error/404.php?c=404 =404;
<span style="white-space:pre"> </span>}
[plain] view
plaincopy
<pre name="code" class="plain"><span style="white-space:pre"> </span>error_page 403 /error/403.php;
<span style="white-space:pre"> </span>error_page 404 /error/404.php;
<span style="white-space:pre"> </span>error_page 500 501 502 503 504 /error/500.php;
}
然后reload下nginx即可
参考http://wiki.nginx.org/HttpCoreModule#try_files
说明下, 我把页面放在了 网站目录下的error文件夹下. 比如网站放在/var/www/ 错误页面就在/var/www/error/403.php ...
测试的话很简单, 403是没权限比如你的网站目录css目录, 图片目录什么的, 404是不存在, 随便输个地址就可以, 500上是服务器的, 这里我停掉php-fpm来测试. 效果如下
aibang.com/show/696530421-425220173/product/15170647.html
aibang.com/show/696530421-425220173/product/15170667.html
aibang.com/show/696530421-425220173/product/15170689.html
aibang.com/show/696530421-425220173/product/15170709.html
aibang.com/show/696530421-425220173/product/15170745.html
aibang.com/show/696530421-425220173/product/15170769.html
aibang.com/show/696530421-425220173/product/15170795.html
aibang.com/show/696530421-425220173/product/15170821.html
aibang.com/show/696530421-425220173/product/15170869.html
aibang.com/show/696530421-425220173/product/15170925.html
aibang.com/show/696530421-425220173/product/15171001.html
aibang.com/show/696530421-425220173/product/15171065.html
aibang.com/show/696530421-425220173/product/15171159.html
aibang.com/show/696530421-425220173/product/15171185.html
aibang.com/show/696530421-425220173/product/15171219.html
aibang.com/show/696530421-425220173/product/15171351.html
aibang.com/show/696530421-425220173/product/15171411.html
aibang.com/show/696530421-425220173/product/15171459.html
aibang.com/show/696530421-425220173/product/15171491.html
aibang.com/show/696530421-425220173/product/15171527.html
aibang.com/show/696530421-425220173/product/15171549.html
aibang.com/show/696530421-425220173/product/15171573.html
aibang.com/show/696530421-425220173/product/15171609.html
aibang.com/show/696530421-425220173/product/15171637.html
aibang.com/show/696530421-425220173/product/15171667.html
aibang.com/show/696530421-425220173/product/15171761.html
aibang.com/show/696530421-425220173/product/15171775.html
aibang.com/show/696530421-425220173/product/15171799.html
aibang.com/show/696530421-425220173/product/15171819.html
aibang.com/show/696530421-425220173/product/15171831.html
aibang.com/show/696530421-425220173/product/15171841.html
aibang.com/show/696530421-425220173/product/15171855.html
aibang.com/show/696530421-425220173/product/15171891.html
aibang.com/show/696530421-425220173/product/15171909.html
aibang.com/show/696530421-425220173/product/15171929.html
aibang.com/show/696530421-425220173/product/15171955.html
aibang.com/show/696530421-425220173/product/15171981.html
aibang.com/show/696530421-425220173/product/15172015.html
aibang.com/show/696530421-425220173/product/15172033.html
aibang.com/show/696530421-425220173/product/15172057.html
aibang.com/show/696530421-425220173/product/15172141.html
aibang.com/show/696530421-425220173/product/15172179.html
aibang.com/show/696530421-425220173/product/15172221.html
aibang.com/show/696530421-425220173/product/15172237.html
aibang.com/show/696530421-425220173/product/15172247.html
aibang.com/show/696530421-425220173/product/15172261.html
aibang.com/show/696530421-425220173/product/15172323.html
aibang.com/show/696530421-425220173/product/15172377.html
aibang.com/show/696530421-425220173/product/15172509.html
aibang.com/show/696530421-425220173/product/15172515.html
k518.com/kunming/zhuankeyiyuan/a9707677.html
k518.com/kunming/zhuankeyiyuan/a9707718.html
k518.com/kunming/zhuankeyiyuan/a9707756.html
k518.com/kunming/zhuankeyiyuan/a9707786.html
k518.com/kunming/zhuankeyiyuan/a9707819.html
k518.com/kunming/zhuankeyiyuan/a9707842.html
k518.com/kunming/zhuankeyiyuan/a9707861.html
k518.com/kunming/zhuankeyiyuan/a9707938.html
k518.com/kunming/zhuankeyiyuan/a9707920.html
k518.com/kunming/zhuankeyiyuan/a9707888.html
k518.com/kunming/zhuankeyiyuan/a9708219.html
k518.com/kunming/zhuankeyiyuan/a9708192.html
k518.com/kunming/zhuankeyiyuan/a9708163.html
k518.com/kunming/zhuankeyiyuan/a9708145.html
k518.com/kunming/zhuankeyiyuan/a9708128.html
k518.com/kunming/zhuankeyiyuan/a9708100.html
k518.com/kunming/zhuankeyiyuan/a9708074.html
k518.com/kunming/zhuankeyiyuan/a9708054.html
k518.com/kunming/zhuankeyiyuan/a9708036.html
k518.com/kunming/zhuankeyiyuan/a9708010.html
k518.com/kunming/zhuankeyiyuan/a9708441.html
k518.com/kunming/zhuankeyiyuan/a9708418.html
k518.com/kunming/zhuankeyiyuan/a9708396.html
k518.com/kunming/zhuankeyiyuan/a9708377.html
k518.com/kunming/zhuankeyiyuan/a9708362.html
k518.com/kunming/zhuankeyiyuan/a9708340.html
k518.com/kunming/zhuankeyiyuan/a9708314.html
k518.com/kunming/zhuankeyiyuan/a9708297.html
k518.com/kunming/zhuankeyiyuan/a9708273.html
k518.com/kunming/zhuankeyiyuan/a9708258.html
k518.com/kunming/zhuankeyiyuan/a9708828.html
k518.com/kunming/zhuankeyiyuan/a9708800.html
k518.com/kunming/zhuankeyiyuan/a9708782.html
k518.com/kunming/zhuankeyiyuan/a9708766.html
k518.com/kunming/zhuankeyiyuan/a9708748.html
k518.com/kunming/zhuankeyiyuan/a9708726.html
k518.com/kunming/zhuankeyiyuan/a9708669.html
k518.com/kunming/zhuankeyiyuan/a9708642.html
k518.com/kunming/zhuankeyiyuan/a9708623.html
k518.com/kunming/zhuankeyiyuan/a9708600.html
k518.com/kunming/zhuankeyiyuan/a9708866.html
k518.com/kunming/zhuankeyiyuan/a9708889.html
k518.com/kunming/zhuankeyiyuan/a9708910.html
k518.com/kunming/zhuankeyiyuan/a9708933.html
k518.com/kunming/zhuankeyiyuan/a9708946.html
k518.com/kunming/zhuankeyiyuan/a9708962.html
k518.com/kunming/zhuankeyiyuan/a9708980.html
k518.com/kunming/zhuankeyiyuan/a9709002.html
k518.com/kunming/zhuankeyiyuan/a9709021.html
k518.com/kunming/zhuankeyiyuan/a9709032.html
只需要在配置
try_files 的时候指定一下就可以了
我的是debian, 在/etc/nginx/site-available/default 里面location /
server{
[plain] view
plaincopy
</pre><pre name="code" class="plain"> location / {
<span style="white-space:pre"> </span>try_files $uri $uri/ /error/404.php?c=404 =404;
<span style="white-space:pre"> </span>}
[plain] view
plaincopy
<pre name="code" class="plain"><span style="white-space:pre"> </span>error_page 403 /error/403.php;
<span style="white-space:pre"> </span>error_page 404 /error/404.php;
<span style="white-space:pre"> </span>error_page 500 501 502 503 504 /error/500.php;
}
然后reload下nginx即可
参考http://wiki.nginx.org/HttpCoreModule#try_files
说明下, 我把页面放在了 网站目录下的error文件夹下. 比如网站放在/var/www/ 错误页面就在/var/www/error/403.php ...
测试的话很简单, 403是没权限比如你的网站目录css目录, 图片目录什么的, 404是不存在, 随便输个地址就可以, 500上是服务器的, 这里我停掉php-fpm来测试. 效果如下
aibang.com/show/696530421-425220173/product/15170647.html
aibang.com/show/696530421-425220173/product/15170667.html
aibang.com/show/696530421-425220173/product/15170689.html
aibang.com/show/696530421-425220173/product/15170709.html
aibang.com/show/696530421-425220173/product/15170745.html
aibang.com/show/696530421-425220173/product/15170769.html
aibang.com/show/696530421-425220173/product/15170795.html
aibang.com/show/696530421-425220173/product/15170821.html
aibang.com/show/696530421-425220173/product/15170869.html
aibang.com/show/696530421-425220173/product/15170925.html
aibang.com/show/696530421-425220173/product/15171001.html
aibang.com/show/696530421-425220173/product/15171065.html
aibang.com/show/696530421-425220173/product/15171159.html
aibang.com/show/696530421-425220173/product/15171185.html
aibang.com/show/696530421-425220173/product/15171219.html
aibang.com/show/696530421-425220173/product/15171351.html
aibang.com/show/696530421-425220173/product/15171411.html
aibang.com/show/696530421-425220173/product/15171459.html
aibang.com/show/696530421-425220173/product/15171491.html
aibang.com/show/696530421-425220173/product/15171527.html
aibang.com/show/696530421-425220173/product/15171549.html
aibang.com/show/696530421-425220173/product/15171573.html
aibang.com/show/696530421-425220173/product/15171609.html
aibang.com/show/696530421-425220173/product/15171637.html
aibang.com/show/696530421-425220173/product/15171667.html
aibang.com/show/696530421-425220173/product/15171761.html
aibang.com/show/696530421-425220173/product/15171775.html
aibang.com/show/696530421-425220173/product/15171799.html
aibang.com/show/696530421-425220173/product/15171819.html
aibang.com/show/696530421-425220173/product/15171831.html
aibang.com/show/696530421-425220173/product/15171841.html
aibang.com/show/696530421-425220173/product/15171855.html
aibang.com/show/696530421-425220173/product/15171891.html
aibang.com/show/696530421-425220173/product/15171909.html
aibang.com/show/696530421-425220173/product/15171929.html
aibang.com/show/696530421-425220173/product/15171955.html
aibang.com/show/696530421-425220173/product/15171981.html
aibang.com/show/696530421-425220173/product/15172015.html
aibang.com/show/696530421-425220173/product/15172033.html
aibang.com/show/696530421-425220173/product/15172057.html
aibang.com/show/696530421-425220173/product/15172141.html
aibang.com/show/696530421-425220173/product/15172179.html
aibang.com/show/696530421-425220173/product/15172221.html
aibang.com/show/696530421-425220173/product/15172237.html
aibang.com/show/696530421-425220173/product/15172247.html
aibang.com/show/696530421-425220173/product/15172261.html
aibang.com/show/696530421-425220173/product/15172323.html
aibang.com/show/696530421-425220173/product/15172377.html
aibang.com/show/696530421-425220173/product/15172509.html
aibang.com/show/696530421-425220173/product/15172515.html
k518.com/kunming/zhuankeyiyuan/a9707677.html
k518.com/kunming/zhuankeyiyuan/a9707718.html
k518.com/kunming/zhuankeyiyuan/a9707756.html
k518.com/kunming/zhuankeyiyuan/a9707786.html
k518.com/kunming/zhuankeyiyuan/a9707819.html
k518.com/kunming/zhuankeyiyuan/a9707842.html
k518.com/kunming/zhuankeyiyuan/a9707861.html
k518.com/kunming/zhuankeyiyuan/a9707938.html
k518.com/kunming/zhuankeyiyuan/a9707920.html
k518.com/kunming/zhuankeyiyuan/a9707888.html
k518.com/kunming/zhuankeyiyuan/a9708219.html
k518.com/kunming/zhuankeyiyuan/a9708192.html
k518.com/kunming/zhuankeyiyuan/a9708163.html
k518.com/kunming/zhuankeyiyuan/a9708145.html
k518.com/kunming/zhuankeyiyuan/a9708128.html
k518.com/kunming/zhuankeyiyuan/a9708100.html
k518.com/kunming/zhuankeyiyuan/a9708074.html
k518.com/kunming/zhuankeyiyuan/a9708054.html
k518.com/kunming/zhuankeyiyuan/a9708036.html
k518.com/kunming/zhuankeyiyuan/a9708010.html
k518.com/kunming/zhuankeyiyuan/a9708441.html
k518.com/kunming/zhuankeyiyuan/a9708418.html
k518.com/kunming/zhuankeyiyuan/a9708396.html
k518.com/kunming/zhuankeyiyuan/a9708377.html
k518.com/kunming/zhuankeyiyuan/a9708362.html
k518.com/kunming/zhuankeyiyuan/a9708340.html
k518.com/kunming/zhuankeyiyuan/a9708314.html
k518.com/kunming/zhuankeyiyuan/a9708297.html
k518.com/kunming/zhuankeyiyuan/a9708273.html
k518.com/kunming/zhuankeyiyuan/a9708258.html
k518.com/kunming/zhuankeyiyuan/a9708828.html
k518.com/kunming/zhuankeyiyuan/a9708800.html
k518.com/kunming/zhuankeyiyuan/a9708782.html
k518.com/kunming/zhuankeyiyuan/a9708766.html
k518.com/kunming/zhuankeyiyuan/a9708748.html
k518.com/kunming/zhuankeyiyuan/a9708726.html
k518.com/kunming/zhuankeyiyuan/a9708669.html
k518.com/kunming/zhuankeyiyuan/a9708642.html
k518.com/kunming/zhuankeyiyuan/a9708623.html
k518.com/kunming/zhuankeyiyuan/a9708600.html
k518.com/kunming/zhuankeyiyuan/a9708866.html
k518.com/kunming/zhuankeyiyuan/a9708889.html
k518.com/kunming/zhuankeyiyuan/a9708910.html
k518.com/kunming/zhuankeyiyuan/a9708933.html
k518.com/kunming/zhuankeyiyuan/a9708946.html
k518.com/kunming/zhuankeyiyuan/a9708962.html
k518.com/kunming/zhuankeyiyuan/a9708980.html
k518.com/kunming/zhuankeyiyuan/a9709002.html
k518.com/kunming/zhuankeyiyuan/a9709021.html
k518.com/kunming/zhuankeyiyuan/a9709032.html
相关文章推荐
- nginx 设置错误的自定义404页面跳转到500
- nginx 设置错误的自定义404页面跳转到500
- nginx 设置错误的自己定义404页面跳转到500
- nginx 自定义404 500 错误页面
- SpringMVC Controller设置400/404/500自定义错误页面
- nginx设置404 500页面跳转至首页,K哥
- nginx 设置 404 500 页面跳转到指定页面
- Nginx配置error_page 404 500等自定义的错误页面
- spring mvc配置自定义错误404,500页面
- Yii自定义错误页面(403,404)和NGINX 配置404错误页面转向
- 自定义错误404页面,自动跳转到站点首页
- APACHE 自定义404错误页面设置方法
- Apache之404错误页面自定义跳转说明
- Beego 1.6+ 错误页面(404,500)自定义重定向
- web应用设置统一友好错误页面,处理404,500等错误
- 自定义 404 与 500 错误页面,URL 地址不会重定向(一)
- 自定义错误404页面,自动跳转到站点首页
- nginx自定义500,502,504错误页面无法跳转【转】
- nginx 设置403、404、等错误页面
- ubuntu 下 wordpress 设置 Permalink 为 自定义结构后出现404页面 nginx - 404 not found page for permalinks