Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NGINX - No input file specified. - php Fast/CGI

Tags:

nginx

Hi I need help in setting config for nginx. I am new to NGINX and facing some issues.

In my sites-available there is default file

It contain below code

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;
}

Above code works perfectly when I write URL

www.test.com/service/public/

when I write

www.test.com/service/public/testservice (testservice is folder within public) it says No input file specified.

How to fix it. thanks in advance.

I tried below, but no luck

http://nginxlibrary.com/resolving-no-input-file-specified-error/
http://blog.martinfjordvald.com/2011/01/no-input-file-specified-with-php-and-nginx/
like image 340
Poonam Bhatt Avatar asked Jan 27 '14 09:01

Poonam Bhatt


5 Answers

You must add "include fastcgi.conf" in

location ~ \.$php{
  #......
  include fastcgi.conf;
}
like image 104
ang yao Avatar answered Nov 02 '22 12:11

ang yao


Resolving "No input file specified" error

If you are using nginx with php-cgi and have followed the standard procedure to set it up, you might often get the “No input file specified” error. This error basically occurs when the php-cgi daemon cannot find a .php file to execute using the SCRIPT_FILENAME parameter that was supplied to it. I’ll discuss about the common causes of the error and it’s solutions. Wrong path is sent to the php-cgi daemon

More often than not, a wrong path (SCRIPT_FILENAME) is sent to the fastCGI daemon. In many of the cases, this is due to a misconfiguration. Some of the setups I have seen are configured like this :

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;
    }
}

Now, there are many things wrong with this configuration. An obvious and glaring issue is the root directive in the location / block. When the root is defined inside the location block, it is available/defined for that block only. Here, the location /images block will not match for any request because it does not have any $document _root defined and we will have to redundantly define root again for it. Obviously, the root directive should be moved out of the location / block and defined in the server block. This way, the location blocks will inherit the value defined in the parental server block. Of course, if you want to define a different $document_root for a location, you can put a root directive in a location block.

Another issue is that the value of the fastCGI parameter SCRIPT_FILENAME is hard-coded. If we change the value of the root directive and move our files somewhere else in the directory chain, php-cgi will return a “No input file specified” error because will not be able to find the file in the hard-coded location which didn’t change when the $document_root was changed. So, we should set SCRIPT_FILENAME as below :

fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;

We should keep in mind that the root directive should be in the server block or else, only the $fastcgi_script_name will get passed as the SCRIPT_FILENAME and we will get the “No input file specified” error.

source(Resolving "No input file specified" error)

like image 24
evergreen Avatar answered Nov 02 '22 12:11

evergreen


Simply restarting my php-fpm solved the issue. As i understand it's mostly a php-fpm issue than nginx.

like image 10
Sam Najian Avatar answered Nov 02 '22 10:11

Sam Najian


Same problem.

Cause : My root wasn't specified in open_basedir.
Fix : Adding my site root directory in :

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

by adding this directive :

php_value[open_basedir] = /my/root/site/dir:/other/directory/allowed
like image 4
Simon Ouellet Avatar answered Nov 02 '22 10:11

Simon Ouellet


I solved it by replacing

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;
like image 3
Fresco Avatar answered Nov 02 '22 10:11

Fresco