【发布时间】:2013-12-24 13:19:15
【问题描述】:
我已经为客户端设置了一个基本服务器,并且说客户端需要基于 nginx(我通常将 apache 用于基于 PHP 的服务器)
这是工作配置。
server {
listen 80;
server_name localhost;
auth_basic "My web site";
auth_basic_user_file "/usr/local/nginx/www_passwd";
location ~ ^/(?:share|conf) {
deny all;
}
location ~ /\.ht {
deny all;
}
location ~ /\.svn {
deny all;
}
location / {
root /var/www;
index index.php index.html index.htm;
}
location ~ \.php$ {
root "/var/www";
fastcgi_pass unix:/etc/phpcgi/php-cgi.socket;
fastcgi_index index.php;
fastcgi_intercept_errors on;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
这对大多数程序都非常有效。 但是我无法捕获 PHP 404 错误,这是模块所必需的。
模块位于名为“extra_app”的目录中
所以我尝试在上面的配置中添加这个:
location ~ ^/extra_app/([a-zA-Z0-9\.])$ {
error_page 404 = /var/www/extra_app/index.php;
root /var/www/extra_app/;
index index.php index.html index.htm;
}
我需要能够从 /extra_app/ 目录中的 php 文件请求中截获 404 错误。 我已将此添加到上述配置的 .php 部分:
fastcgi_intercept_errors on;
这没有任何效果。 (是的,我重启了nginx服务!)
有人知道解决办法吗?
谢谢!
[编辑]
我不确定是否需要 404 错误页面...也许可以为 nginx 编写“mod_rewrite”规则?我是 nginx 的新手,我什至不确定你是否可以重写 url...
【问题讨论】:
-
我认为
error_page可以实现这一点。您可以阅读original document。
标签: php linux nginx http-status-code-404 config