我的自定义错误页面曾经工作,但是现在每当抛出错误页面时我都会收到错误No input file specified
;但是如果我直接访问它,例如www.example.com/404
,它就会正确显示。
这是为什么?我看不出配置有什么问题。我的所有页面都在同一个文件夹中,所以我看不出我是如何得到这个错误的。
ssl_certificate /etc/nginx/ssl/bundle.crt;
ssl_certificate_key /etc/nginx/ssl/myserver.key;
ssl_session_timeout 10m;
ssl_session_cache shared:SSL:10m;
ssl_dhparam /etc/nginx/ssl/dhparams.pem;
ssl_protocols TLSv1.1 TLSv1.2;
ssl_ciphers 'ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-$
ssl_prefer_server_ciphers on;
ssl_stapling on;
ssl_stapling_verify on;
# HTTPS redirect
server {
listen 80;
server_name www.example.com;
rewrite ^ https://www.example.com$request_uri? permanent;
add_header Strict-Transport-Security "max-age=15768000; includeSubDomains";
resolver 192.0.2.1;
}
server {
listen 80;
listen 443 ssl;
keepalive_timeout 70;
access_log /var/www/example.com/logs/access.log;
error_log /var/www/example.com/logs/error.log;
root /var/www/example.com/public_html/example/public/_main;
server_name example.com;
# HSTS - 6 months
add_header Strict-Transport-Security "max-age=15768000; includeSubDomains";
resolver 192.0.2.1;
error_page 400 = /400.php;
error_page 401 = /401.php;
error_page 403 = /403.php;
error_page 404 = /404.php;
error_page 500 = /500.php;
error_page 503 = /503.php;
# Remove trailing slash to please routing system.
if (!-d $request_filename) {
rewrite ^/(.+)/$ /$1 permanent;
}
location /400.php {
internal;
}
location /401.php {
internal;
}
location /403.php {
internal;
}
location /404.php {
internal;
}
location /500.php {
internal;
}
location /503.php {
internal;
}
location = / {
index landing.php;
}
location / {
try_files $uri $uri.php?$query_string;
}
location /assets/images/ {
valid_referers none blocked example.com *.example.com;
if ($invalid_referer) {
return 403;
}
}
location ~ \.php$ {
try_files $uri =404;
include /etc/nginx/fastcgi_params;
if ($uri !~ "^/assets/images/") {
fastcgi_pass unix:/var/run/php-fastcgi/php-fastcgi.socket;
}
fastcgi_index landing.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
答案 0 :(得分:0)
我终于想出了如何解决这个问题。在location ~ \.php$ { }
块中,您需要添加fastcgi_intercept_errors on;
。最终看起来像这样:
location ~ \.php$ {
try_files $uri =404;
include /etc/nginx/fastcgi_params;
if ($uri !~ "^/assets/images/") {
fastcgi_pass unix:/var/run/php-fastcgi/php-fastcgi.socket;
}
fastcgi_index landing.php;
fastcgi_intercept_errors on;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
答案 1 :(得分:0)
我的解决方法是这一行:
try_files $uri =404;