1
我面對同樣可怕的「沒有指定輸入文件」。 NGINX中的消息。下面給出了我試圖實現的簡要說明。在NGINX中遇到錯誤而不是404錯誤
- 用「.PHP」擴展名結尾的任何現有的網址應爲404錯誤[工作]
- 任何現有的URL沒有「.php」結尾將執行該文件顯示[工作]
- 任何子虛烏有網址應該拋出404錯誤[不能正常工作]。在這種情況下,NGINX拋出的錯誤是「沒有指定輸入文件」。
我訪問過並試圖實施位於Nginx + php fastcgi showing "No input file specified." instead of 404的解決方案,但這並未解決我的問題。
我真的不知道如何呈現404頁點的情況下,3
在/ etc/nginx的/啓用的站點 - /默認低於
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;
}
}
給出文件請保持在內容介意我只是一個初學者而不是專家。任何幫助表示讚賞。
在缺少的塊中添加'try_files $ uri.php = 404;'會爲先前提供的所有請求引發404錯誤。 try_files存在於其上的另一個塊中。 – user4943000
對不起,'try_files'改變了URI。更新的答案使用'if'語句代替。 –
非常感謝@RichardSmith。這是我需要的。 – user4943000