【 在 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.*