Reputation: 492
I have in nginx.conf
upstream php-fpm7.0
{
server unix:/run/php-fpm/php7.sock;
}
I have in conf.d/default.conf
location ~ \.php$ {
include php-fpm;
}
I have in php-fpm
fastcgi_pass php-fpm7.0;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
set $path_info $fastcgi_path_info;
fastcgi_param PATH_INFO $path_info;
# Additional variables
fastcgi_index index.php;
But i get error 404. When i comment
#location ~ \.php$ {
# include php-fpm;
#}
files are available
Error even if
location ~ \.php$ {
fastcgi_pass unix:/run/php-fpm/php7.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream
The same error if not using socket:
fastcgi_pass 127.0.0.1:9000;
Centos 7
Update 1.
After i used:
fastcgi_param SCRIPT_FILENAME $document_root/index.php;
fastcgi_param SCRIPT $fastcgi_script_name;
fastcgi_param FOLDER $document_root;
fastcgi_param FOLDER_SCRIPT $document_root$fastcgi_script_name;
I got $_SERVER['SCRIPT']
/index.php
and $_SERVER['FOLDER']
/home/www/m-a-x/www
and $_SERVER['FOLDER_SCRIPT']
/home/www/m-a-x/www/index.php
When i back
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
all works. Mystery.
Upvotes: 2
Views: 6774
Reputation: 21
You can always check nginx variables by adding them to return statement, for example:
location / {
return 200 $document_root$fastcgi_script_name;
}
Open the URL, a file will be downloaded, file will contain variables returned by nginx. For example /srv/www/index.php
Check that nginx/php-fpm user group has access to the file:
sudo -u www stat /srv/www/index.php
Set permissions to read and execute the files for the www user group all along the path.
chmod g+x /srv
chmod g+x /srv/www
chmod g+x /srv/www/index.php
Upvotes: 2