Nginx + PHP - входной файл не указан
Распространенное сообщение об ошибке 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; } } }