【发布时间】:2017-03-23 04:49:22
【问题描述】:
我面临着同样可怕的“未指定输入文件”。 NGINX 中的消息。下面是我想要实现的目标的简要说明。
- 任何以“.php”扩展名结尾的现有 URL 都应显示为 404 错误 [工作中]
- 任何没有“.php”扩展名的现有 URL 都将执行文件 [工作]
- 任何不存在的 URL 都应该抛出 404 错误 [不工作]。在这种情况下,NGINX 抛出的错误是“没有指定输入文件”。
我已访问并尝试实施位于 Nginx + php fastcgi showing "No input file specified." instead of 404 的解决方案,但这并没有解决我的问题。
我真的不确定如何在第 3 点的情况下呈现 404 页面。
/etc/nginx/sites-enabled/default 文件的内容如下
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html/example.com;
index index.php index.html index.htm;
server_name example.com;
error_page 404 /error/custom_404;
location / {
try_files $uri $uri/ @missing;
}
location ~ (\.php$|myadmin) {
return 404;
}
location @missing {
fastcgi_param SCRIPT_FILENAME "$document_root$uri.php";
fastcgi_param PATH_TRANSLATED "$document_root$uri.php";
fastcgi_param QUERY_STRING $args;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}
location ~ /\.ht {
deny all;
}
}
请记住,我只是一个初学者而不是专家。任何帮助表示赞赏。
【问题讨论】: