1

I am facing the same dreaded "No input file specified." message in NGINX. A brief description of what I am trying to achieve is as given below.

  1. Any existing URL ending with ".php" extension should show as 404 error [working]
  2. Any existing URL without ".php" extension will execute the file [working]
  3. Any non-existent URL should throw 404 error [not working]. In this case the error thrown by NGINX is "No input file specified."

I have visited and tried to implement the solution located at Nginx + php fastcgi showing "No input file specified." instead of 404 but this did not solve my problem.

I am really not sure how to render 404 page in case of point 3.

Contents of /etc/nginx/sites-enabled/default file is given below

server {
    listen 80 default_server;
    listen [::]:80 default_server;
    root /var/www/html/example.com;
    index index.php index.html index.htm;
    server_name example.com;
    error_page 404 /error/custom_404;

    location / {
        try_files $uri $uri/  @missing;
    }

    location ~ (\.php$|myadmin) {
    return 404;
    }

    location @missing {
            fastcgi_param SCRIPT_FILENAME "$document_root$uri.php";
            fastcgi_param PATH_TRANSLATED "$document_root$uri.php";
            fastcgi_param QUERY_STRING    $args;
            fastcgi_pass unix:/run/php/php7.0-fpm.sock;
            fastcgi_index index.php;
            include fastcgi_params;
            }

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php7.0-fpm.sock;
    }

    location ~ /\.ht {
        deny all;
    }
}

Please keep in mind that I am just a beginner and not an expert. Any help is appreciated.

Community
  • 1
  • 1
user4943000
  • 111
  • 12

1 Answers1

1

Your location @missing block does nothing to verify the existence of the file before passing it to php-fpm. Add a check for file existence:

location @missing {
    if (!-f $document_root$uri.php) { return 404; }
    ...
}

See this document for more, and this caution on the use of if.

Richard Smith
  • 45,711
  • 6
  • 82
  • 81