Nginx php-fpm No input file specified

When accessing PHP files from location block that have different document root specified using alias, i get error

No input file specified.

nginx php-fpm  error

Here is the Nginx config i used

Advertisement

server {
    listen 80;
    server_name lab.test;
    root /www/lab.test/html;
    autoindex on;
    index index.php;

    location /ok/ {
        alias /www/serverok.test/html/;

        location ~ \.php$ {
            include snippets/fastcgi-php.conf;
            fastcgi_intercept_errors on;
            fastcgi_buffers 16 16k;
            fastcgi_buffer_size 32k;
            fastcgi_pass unix:/run/php/php7.4-fpm-boby.sock;
        }

    }

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_intercept_errors on;
        fastcgi_buffers 16 16k;
        fastcgi_buffer_size 32k;
        fastcgi_pass unix:/run/php/php7.4-fpm-boby.sock;
    }
}

If I access an HTML file or any non-PHP file, it works properly from/ok/ location.

The problem is due to php-fpm not able to find the proper path when using the alias. If I put the PHP files inside a folder /ok/, it worked.

To fix the problem, add the following code before fastcgi_pass

fastcgi_param    SCRIPT_FILENAME    $request_filename;
fastcgi_param    SCRIPT_NAME        $fastcgi_script_name;

Example

nginx php-fpm error no input
Add a comment

Leave a Reply

Your email address will not be published. Required fields are marked *

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Advertisement