Nginx & PHP-FPM - Unable to open primary script ERROR
The important parameter here is the SCRIPT_FILENAME parameter. you can change that line to $document_root/share.php or, if you want, /var/www/domain.com/share.php The $fastcgi_script_name is using the requestm location as the path
Regards
Related videos on Youtube
Georgi Vasilev
Updated on September 18, 2022Comments
-
Georgi Vasilev over 1 year
I have a blog with some rewrite rules when in comes to viewing single posts. The viewing is handled by a file named view.php. I am using some rewrite rules in my vhost config as follows:
location /view { rewrite ^/view/([^/.]+)?/?(.*) /view1.php?pid=$1&$query_string; }
This makes the URL look like this:
http://domain.com/view/xxxx
where xxxx is the post ID. On that same page I have a social share plugin which includes a file named share.php located in the same directory as the view.php file. The plugin works fine, however I am receiving the following error in my log:
FastCGI sent in stderr: "Unable to open primary script: /var/www/domain.com/view/xxxx/share.php (No such file or directory)"
I am guessing it has something to do with the above rewrite rule in my nginx configuration file. How can I resolve this? Should I add a specific rewrite rule for the share.php file in my vhost configuration file?
Here is my php conf:
location ~ \.php$ { root /var/www/domain.com; fastcgi_busy_buffers_size 256k; fastcgi_temp_file_write_size 256k; fastcgi_intercept_errors on; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_ignore_client_abort on; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; }
-
Georgi Vasilev over 10 yearsThis would render all other php files in my domain's folder inaccessible/not-working.