“no input file specified”错误原因和解决方法
No Input File Specified这意味着你没有将要执行的php文件的路径传递给php-fpm.这是由SCRIPT_FILENAME参数传递的.
出于安全考虑,它有好处cgi.fix_pathinfo=0.Symfony将与它合作不用担心.
php块是重要的部分.
location ~ .php$ 这意味着如果uri以”.php”结尾,它将被传递给php.现在如果有一个图像并且一些攻击者用它添加”.php”,启用了fix_pathinfo它将被传递给php处理程序并且可以在服务器中执行任意代码.所以我建议你添加cgi.fix_pathinfo=0php.ini并fastcgi_split_path_info ^(.+.php)(/.+)$;从nginx中删除.
我用于symfony2的配置是,
server { listen 80; server_name projectname.local; root /Users/sarim/Sites/php55/projectname/web; index app_dev.php index.html index.htm; location / { try_files $uri $uri/ /app_dev.php?$args; } location ~ ^/(app|app_dev|config).php(/|$) { fastcgi_pass unix:/usr/local/var/run/php55.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } }
在这里检查location /块.try_files $ uri $ uri /确保提供静态文件.然后如果它不是静态文件,则传递给/app_dev.php.
现在检查php位置块,只能访问app或app_dev或config.php.没有任意文件执行.现在重要的fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;路线.它应该始终是$ document_root $ fastcgi_script_name.这样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;