水木社区手机版
首页
|版面-Web开发(WebDev)|
新版wap站已上线
返回
1/1
|
转到
主题:nginx配置请教
楼主
|
skybluee
|
2010-02-04 13:28:58
|
只看此ID
配置目标:
1、当存在file.php时,访问/file.html和/file.php都实际访问file.php
2、当不存在file.php时,访问/file.html和/file.php返回指定的404页
3、访问其它不存在的文件时,返回相同的404页
目前的配置:
location / {
root xxx;
index xxx;
rewrite ^/(.*)\.html /$1.php last;
}
location ~ \.php {
fastcgi_pass xxx
...
}
error-page 404 /error-404.html;
location /error-404.html {
root xxx;
internal;
}
目前配置的情况:
1、目标1实现
2、目标3实现
3、当不存在file.php时,访问/file.html和/file.php没有返回指定的404页,只是404码
我个人的分析是,请求/file.html时,被重写为/file.php,当请求传给fastcgi之后找不到文件,就不再回来用404页面了,是否有办法让fastcgi部分也有个404页呢?
尝试使用 try_files:
location ~ ^/(.*)\.html {
try_files /$1.php @error;
}
location @error {
root xxx;
index error-404.html
}
存在file.php的情况下,访问/file.html返回php文件,没有交给fastcgi就返回了
--
FROM 222.131.80.*
1楼
|
skybluee
|
2010-02-04 13:46:14
|
只看此ID
【 在 skybluee (天蓝) 的大作中提到: 】
: 标 题: nginx配置请教
: 发信站: 水木社区 (Thu Feb 4 13:39:56 2010), 站内
:
: 配置目标:
: 1、当存在file.php时,访问/file.html和/file.php都实际访问file.php
: 2、当不存在file.php时,访问/file.html和/file.php返回指定的404页
: 3、访问其它不存在的文件时,返回相同的404页
:
: 目前的配置:
: location / {
: root xxx;
: index xxx;
: rewrite ^/(.*)\.html /$1.php last;
: }
: location ~ \.php {
: fastcgi_pass xxx
: ...
: }
: error-page 404 /error-404.html;
: location /error-404.html {
: root xxx;
: internal;
: }
:
: 目前配置的情况:
: 1、目标1实现
: 2、目标3实现
: 3、当不存在file.php时,访问/file.html和/file.php没有返回指定的404页,只是404码
:
: 我个人的分析是,请求/file.html时,被重写为/file.php,当请求传给fastcgi之后找不到文件,就不再回来用404页面了,是否有办法让fastcgi部分也有个404页呢?
在这里我还曾经尝试这样写
location ~ ^/(.*)\.html {
root xxx;
if (-e $1.php) {
rewrite ^/(.*)\.html /$1.php last;
}
}
但在存在file.php的情况下,访问/file.html返回404
: 尝试使用 try_files:
: location ~ ^/(.*)\.html {
: try_files /$1.php @error;
: }
: location @error {
: root xxx;
: index error-404.html
: }
: 存在file.php的情况下,访问/file.html返回php文件,没有交给fastcgi就返回了
: --
: ▆██◣ █ █ ◆
: ◢ █ ◢███ ◢██◣ ███◣ █ ◢██◣ ◢██◣
: ▊ ◢◣ ▋ █ █ █ █ █ █ █ █ █ █
: ▍ ◥▄◤ █ █ ████ █ █ █ ◢███ █ █
: ▍ █ █ █ █ █ █ █ █ █ █
: ◥▄▂ ◥█◤█ ◥██◤ ◥██◤ █ ◥█◤█ █ █
:
:
: ※ 来源:·水木社区 newsmth.net·[FROM: 222.131.80.*]
--
FROM 222.131.80.*
2楼
|
JulyClyde
|
2010-02-04 14:04:19
|
只看此ID
http://wiki.nginx.org/NginxHttpFcgiModule#fastcgi_intercept_errors
你看这个行不?
【 在 skybluee (天蓝) 的大作中提到: 】
: 配置目标:
: 1、当存在file.php时,访问/file.html和/file.php都实际访问file.php
: 2、当不存在file.php时,访问/file.html和/file.php返回指定的404页
: ...................
--
FROM 124.205.200.*
3楼
|
skybluee
|
2010-02-04 14:14:49
|
只看此ID
就是这个,谢谢!
【 在 JulyClyde (Be stewed/被炖了) 的大作中提到: 】
:
http://wiki.nginx.org/NginxHttpFcgiModule#fastcgi_intercept_errors
: 你看这个行不?
--
FROM 222.131.80.*
4楼
|
JulyClyde
|
2010-02-04 14:21:50
|
只看此ID
原来我还不明白这个选项是干啥的呢
现在明白了
【 在 skybluee (天蓝) 的大作中提到: 】
: 就是这个,谢谢!
--
FROM 124.205.200.*
5楼
|
skybluee
|
2010-02-04 15:17:55
|
只看此ID
它的变量名许多都不太好理解
【 在 JulyClyde (Be stewed/被炖了) 的大作中提到: 】
: 原来我还不明白这个选项是干啥的呢
: 现在明白了
--
FROM 222.131.80.*
6楼
|
JulyClyde
|
2010-02-04 16:14:54
|
只看此ID
文档似乎不是科技英语。有点晦涩
你回头写文章介绍介绍这个参数吧
【 在 skybluee (天蓝) 的大作中提到: 】
: 它的变量名许多都不太好理解
--
FROM 124.205.200.*
1/1
|
转到
选择讨论区
首页
|
分区
|
热推
BYR-Team
©
2010.
KBS Dev-Team
©
2011
登录完整版