常见的Nginx + PHP错误消息“未指定输入文件。”
nginx.conf
http {
include mime.types;
default_type application/octet-stream;
server {
listen 80;
server_name localhost;
location / {
root www;
index index.html index.htm;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9999;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
}
经过Nginx 1.12.1 + PHP 7.1测试
解
PHP无法找到要执行的.php
文件,因为location / {}
中的根文件路径不适用于location ~ \.php$
。
要解决此问题,请将根文件路径移动到服务器块,如下所示:
nginx.conf
http {
include mime.types;
default_type application/octet-stream;
server {
listen 80;
server_name localhost;
# Move the root file path to server block.
root www;
location / {
#root www;
index index.html index.htm;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9999;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
}
参考文献
翻译自: https://mkyong.com/nginx/nginx-php-no-input-file-specified/