NGINX - 未指定输入文件。 - php Fast / CGI

时间:2014-01-27 09:35:38

标签: nginx

您好我需要帮助设置nginx的配置。我是NGINX的新手,面临一些问题。

在我的sites-available中有default个文件

它包含以下代码

server {
    server_name www.test.com test.com;
    access_log /sites/test/logs/access.log;
    error_log /sites/test/logs/error.log;
    root /sites/test;

 location ~ / {

index index.php
    include /etc/nginx/fastcgi_params;
    fastcgi_pass  127.0.0.1:9000;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}

上面的代码在我写URL时非常有效

www.test.com/service/public/

当我写

www.test.com/service/public/testservice(testservice是公共文件夹),它说No input file specified.

如何修复它。 提前谢谢。

我在下面试过,但没有运气

http://nginxlibrary.com/resolving-no-input-file-specified-error/
http://blog.martinfjordvald.com/2011/01/no-input-file-specified-with-php-and-nginx/

18 个答案:

答案 0 :(得分:23)

您必须在

中添加“include fastcgi.conf”
location ~ \.$php{
  #......
  include fastcgi.conf;
}

答案 1 :(得分:14)

解析"未指定输入文件"错误

如果您正在使用带有php-cgi的nginx并且已按照标准过程进行设置,那么您可能经常会收到“未指定输入文件”错误。当php-cgi守护程序无法使用提供给它的SCRIPT_FILENAME参数找到要执行的.php文件时,基本上会发生此错误。我将讨论错误的常见原因及其解决方案。 错误的路径被发送到php-cgi守护程序

通常会将错误的路径(SCRIPT_FILENAME)发送到fastCGI守护程序。在许多情况下,这是由于配置错误造成的。我见过的一些设置配置如下:

server {
    listen   [::]:80;
    server_name  example.com www.example.com;
    access_log  /var/www/logs/example.com.access.log;  

    location / {
        root   /var/www/example.com;
        index  index.html index.htm index.pl;
    }

    location /images {
        autoindex on;
    }

    location ~ \.php$ {
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  /var/www/example.com$fastcgi_script_name;
        include fastcgi_params;
    }
}

现在,这个配置有很多问题。一个明显且明显的问题是位置/块中的根指令。当在位置块内定义根时,它仅为该块可用/定义。这里,位置/图像块不匹配任何请求,因为它没有定义任何$ document _root,我们将不得不为它再次冗余地定义root。显然,root指令应该移出位置/块并在服务器块中定义。这样,位置块将继承父级服务器块中定义的值。当然,如果要为位置定义不同的$ document_root,可以将根指令放在位置块中。

另一个问题是fastCGI参数SCRIPT_FILENAME的值是硬编码的。如果我们更改root指令的值并将我们的文件移动到目录链中的其他位置,php-cgi将返回“未指定输入文件”错误,因为无法在硬编码位置找到该文件$ document_root更改时更改。因此,我们应该将SCRIPT_FILENAME设置如下:

fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;

我们应该记住root指令应该在服务器块中,否则只有$ fastcgi_script_name将作为SCRIPT_FILENAME传递,我们将得到“No input file specified”错误。

source(Resolving "No input file specified" error)

答案 2 :(得分:6)

只需重新启动我的php-fpm解决了这个问题。据我所知,它主要是一个php-fpm问题,而不是nginx。

答案 3 :(得分:2)

同样的问题。

原因:我的root未在 open_basedir 中指定。

修复:将我的网站根目录添加到:

/etc/php5/fpm/pool.d/mysite.conf<br>

添加此指令:

php_value[open_basedir] = /my/root/site/dir:/other/directory/allowed

答案 4 :(得分:1)

server {
    server_name www.test.com test.com;
    access_log /sites/test/logs/access.log;
    error_log /sites/test/logs/error.log;
    root /sites/test;

 location ~ / {

index index.php
    include /etc/nginx/fastcgi_params;
    fastcgi_pass  127.0.0.1:9000;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME `$document_root/service/public$fastcgi_script_name`;
}

答案 5 :(得分:1)

我通过替换

解决了这个问题
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

$ document_root with C:\ MyWebSite \ www \

fastcgi_param SCRIPT_FILENAME C:\MyWebSite\www\$fastcgi_script_name;

答案 6 :(得分:1)

我尝试了上述所有选项,但最终找到了解决方案。 在我的服务器上,.php文件设置为所有人均可读取,但是当我将php-fpm设置为在与nginx相同的用户下运行时,它可以工作。我在/etc/php/7.2/fpm/pool.d/www.conf和设置的配置文件

中进行了更改

user = nginx group = nginx

,然后重新加载php-fpm进程 希望这会有所帮助

答案 7 :(得分:0)

好吧,我是菜鸟,但只是分享我遇到的事情。

我使用 Linode 设置 Laravel Forge 以从我的 github 存储库运行静态网站。

通过 SSH 连接到我的 Linode 并验证我的 html 已更新,但是在访问我的 linode 的公共 IP 时,我看到错误消息“未指定输入文件。

转到我伪造的 Nginx 配置文件并删除“公共”一词,所以现在是

root /home/forge/default;

在forge内重启nginx服务器并重新部署,现在可以访问了。

答案 8 :(得分:0)

这可能是因为使用尾部斜杠,NGinx会尝试查找默认索引文件,该文件可能是index.html而没有配置。如果没有尾部斜杠,它会尝试匹配他找不到的文件测试服务。这个和/或您在testservice文件夹中没有任何默认索引文件。

尝试将此行添加到server配置中:

index  index.php index.html index.htm; // Or in the correct priority order for you

希望这有帮助!

修改

我的回答不是很清楚,请看这个例子来理解我的意思

listen 80;

    server_name glo4000.mydomain.com www.glo4000.mydomain.com;


    access_log  /var/log/nginx/glo-4000.access.log;
    error_log /var/log/nginx/glo-4000.error_log;

    location / {
        root   /home/ul/glo-4000/;
        index  index.php index.html index.htm;
    }

    location ~ \.php$ {

        include fastcgi_params;
        fastcgi_pass   unix:/tmp/php5-fpm.sock;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME /home/ul/glo-4000/$fastcgi_script_name;
    }
}

答案 9 :(得分:0)

对于localhost-我忘了写C:\Windows\System32\drivers\etc\hosts

127.0.0.1 localhost

还从ngnix.conf中的其他服务器上删除了proxy_pass http://127.0.0.1;

答案 10 :(得分:0)

在Windows中使用

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

没有放-b

php-cgi.exe -b 127.0.0.1:9000

答案 11 :(得分:0)

好的, 我假设您在Ubuntu 16或更高版本上使用php7.2(或更高版本)

如果这些都不起作用,您必须知道nginx-fastCGI对同一服务器上托管的不同站点使用了不同的pid和.sock。

要解决“未指定输入文件”问题,必须告诉nginx yoursite.conf文件使用哪个袜子文件。

  1. 取消注释默认的fastcgi_pass unix:/var/run/php7.2-fpm.sock,请确保在conf文件中使用以下指令,

    location / {
        try_files $uri $uri/ /index.php$is_args$args;
    }
    location ~ \.php$ {
            try_files $uri /index.php =404;
            #fastcgi_pass unix:/var/run/php7.2-fpm.sock;
            fastcgi_pass unix:/var/php-nginx/158521651519246.sock/socket;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include fastcgi_params;
    }
    
  2. 使用ls -la /var/php-nginx/查看sock和pid文件列表(如果您最近添加了文件,它应该是列表中的最后一个文件)

3。复制.sock文件的文件名(通常为15位数字)并将其粘贴到您的location ~ \.php指令中

fastcgi_pass unix:/var/php-nginx/{15digitNumber}.sock/socket;

并重新启动nginx。 让我知道它是否有效。

答案 12 :(得分:0)

此答案对我没有帮助,我的PHP管理员仍然向我显示“未指定输入文件”错误。 但是我知道我以前更改过php版本。 所以,我找到了原因:它不是nginx,它是php.ini doc_root参数! 我发现

  

doc_root =

在php.ini中将其更改为

  

; doc_root =

此补丁发布后,我的管理员工作正常。

答案 13 :(得分:0)

我的情况: SELinux已启用并拒绝执行我的脚本的php-fpm。

诊断: Temporarilly禁用SELinux并查看问题是否消失。

$ sudo setenforce permissive
### see if PHP scripts work ###
$ sudo setenforce enforcing

解决方案:将PHP目录放在httpd_sys_content_t上下文中。您可以chcon使用semanage或通过$ sudo semanage fcontext -a -t httpd_sys_content_t "/srv/myapp(/.*)?" $ sudo restorecon -R -F /srv/myapp 保持更改:

httpd_sys_rw_content_t

您可以使用需要写入权限的上下文$(window).scroll(function() { if($(window).scrollTop() + $(window).height() >= $(document).height()){ //Your code here } });

答案 14 :(得分:0)

同样的问题。

原因旧的open_basedir设置与备份中的恶意user.ini文件一起复制

解决方案将其删除

答案 15 :(得分:0)

我尝试了上面的所有设置,但这解决了我的问题。 你必须定义nginx来检查php文件是否确实存在于该位置。我发现try_files $uri = 404;解决了这个问题。

location ~ \.php$ {
        try_files  $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php5-fpm.sock; 
        include fastcgi_params;
        fastcgi_index index.php;
}

答案 16 :(得分:0)

我有同样的错误,我的问题是,我在我的加密主目录中有我的php文件。我用www-data用户运行我的fpm,即使文件的权限是正确的,该用户也无法读取php文件。解决方案是我与拥有主目录的用户运行fpm。这可以在下面的文件中更改:

/etc/php5/fpm/pool.d/www.conf

希望这会对你有所帮助:)。

答案 17 :(得分:-1)

如果有人仍然遇到问题......我通过这样纠正解决了问题:

在网站配置文件中(例如:/etc/nginx/conf.d/SITEEXAMPLE.conf)我有以下一行:

fastcgi_param  SCRIPT_FILENAME  /usr/share/nginx/html$fastcgi_script_name;

发生错误是因为我的网站不在&#34; /usr/share/nginx/html&#34;文件夹,但在文件夹中:/var/www/html/SITE/

因此,更改该部分,将代码保留如下。注意:对于在/var/www/html/YOUR_SITE/

中使用网站标准的用户
fastcgi_param  SCRIPT_FILENAME  /var/www/html/YOUR_SITE/$fastcgi_script_name;