为什么自定义错误页在我的nginx配置中不起作用?
我有以下服务器块:为什么自定义错误页在我的nginx配置中不起作用?,nginx,config,Nginx,Config,我有以下服务器块: server { listen 80; server_name utsav-dev.domain.org; root /var/www/domain-utsav-dev/web; access_log /var/log/nginx/domain-utsav-dev-access.log; error_log /var/log/nginx/domain-utsav-dev-error.log error; error_page
server {
listen 80;
server_name utsav-dev.domain.org;
root /var/www/domain-utsav-dev/web;
access_log /var/log/nginx/domain-utsav-dev-access.log;
error_log /var/log/nginx/domain-utsav-dev-error.log error;
error_page 404 = /var/www/domain/web/50x.html;
set $thttps $https;
set $tscheme $scheme;
if ($http_x_forwarded_proto = http) {
set $thttps off;
set $tscheme "http";
}
if ($http_x_forwarded_proto = HTTP) {
set $thttps off;
set $tscheme "http";
}
index app.php index.html index.htm;
try_files $uri $uri/ @rewrite;
location @rewrite {
rewrite ^/(.*)$ /app.php/$1;
}
# CSS and Javascript
location ~* \.(?:css|js)$ {
expires 86400;
access_log off;
add_header Cache-Control "public";
}
location ~ \.php {
fastcgi_index app.php;
fastcgi_pass unix:/var/run/php5-fpm.sock;
include fastcgi_params;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param APPLICATION "www";
fastcgi_param APPLICATION_ENV "dev";
fastcgi_param PDFLIBLICENSEFILE "/etc/php5/fpm/pdflib.license";
fastcgi_param HTTPS $thttps;
}
location ~ /\.ht {
deny all;
}
chunked_transfer_encoding off;
}
现在,根据脚本,如果找不到页面,nginx应该在内部重定向到50x.html,但当我尝试打开时,会出现错误“未找到文件”,而不是我预期的自定义404页面。为什么?尝试将
fastcgi\u intercept\u错误设置为打开代码>在您的fastcgi位置
fastcgi_intercept_错误打开|关闭;
确定代码大于或等于300的FastCGI服务器响应是应传递给客户端,还是应重定向到nginx以使用error_page指令进行处理。
当您访问http://utsav-dev.domain.org/blah.html
:
- 首先检查每个位置。没人打
- 它将遍历
try\u文件
。点击@rewrite位置
- uri更改为/app.php/blah.html
- 点击fastcgi位置
您应该将fastcgi\u intercept\u错误设置为on
要让错误页面
工作可能需要重写^/(.*)$/app.php?r=$1
或尝试文件$uri$uri/@rewrite=404
@myninjaname:rewrite会影响自定义错误页面的位置吗?看起来很像,但是使用app.php/$1
而不是?r=$1
(或者@rewrite中的fastcgi\u param QUERY\u STRING q=$uri&$args
),您会得到未找到的文件错误(我认为是来自fastcgi,而不是nginx,因此它不会出现404)。