网站首页 > 精选文章 / 正文
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; 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; } } }
Tags:nginx启动指定配置文件
猜你喜欢
- 2025-05-15 Godaddy购买SSL之后Nginx配置流程以及各种错误的解决
- 2025-05-15 Nginx负载均衡配置与调优:Java应用的性能魔法
- 2025-05-15 nginx服务器负载均衡配置
- 2025-05-15 Nginx主从配置详解(图文全面总结)
- 2025-05-15 后端实践:Nginx日志配置(超详细)
- 2025-05-15 systemd service之:服务配置文件编写(2)
- 2025-05-15 Nginx 配置太复杂?这个开源项目让你在Web中就搞定
- 2025-05-15 nginx常用命令及简单配置
- 2025-05-15 Nginx负载均衡配置与Java应用的完美结合
- 2025-05-15 Java程序员眼中的Nginx反向代理配置指南