Nginx + PHP - Keine Eingabedatei angegeben

Nginx + PHP - Keine Eingabedatei angegeben

Eine häufige Nginx + PHP-Fehlermeldung "Keine Eingabedatei angegeben."

image

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

    }

}

Getestet mit Nginx 1.12.1 + PHP 7.1

Lösung

PHP kann die auszuführende.php-Datei nicht finden, da der Stammdateipfad inlocation / {} nicht fürlocation ~ \.php$ gilt.

Verschieben Sie den Stammdateipfad wie folgt in den Serverblock, um das Problem zu beheben:

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

    }

}