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.
Here is the Nginx config i used
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
Back to Nginx