Recently I installed the latest version of Nginx and looks like I'm having hard time running PHP with it.
Here is the configuration file I'm using for the domain:
server {
listen 80;
server_name localhost;
location / {
root /usr/share/nginx/html;
index index.php;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
include fastcgi_params;
}
}
Here is the error I'm getting on the error log file:
FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream
In my case the PHP-script itself returned 404 code. Had nothing to do with nginx.
Try another *fastcgi_param* something like
For me, problem was Typo in location path.
Maybe first thing to check out for this kind of problem
Is path to project.
I had been having the same issues, And during my tests, I have faced both problems:
1º: "File not found"
and
2º: 404 Error page
And I found out that, in my case:
I had to mount volumes for my public folders both on the Nginx volumes and the PHP volumes.
If it's mounted in Nginx and is not mounted in PHP, it will give: "File not found"
Examples (Will show "File not found error"):
If it's mounted in PHP and is not mounted in Nginx, it will give a 404 Page Not Found error.
Example (Will throw 404 Page Not Found Error):
And this would work just fine (mounting on both sides) (Assuming everything else is well configured and you're facing the same problem as me):
Also here's a Full working example project using Nginx/Php, for serving multiple sites: https://github.com/Pablo-Camara/simple-multi-site-docker-compose-nginx-alpine-php-fpm-alpine-https-ssl-certificates
I hope this helps someone, And if anyone knows more about this please let me know, Thanks!
in case it helps someone, my issue seems to be just because I was using a subfolder under my home directory, even though permissions seem correct and I don't have SELinux or anything like that. changing it to be under /var/www/something/something made it work.
(if I ever found the real cause, and remember this answer, I'll update it)
I had the "file not found" problem, so I moved the "root" definition up into the "server" bracket to provide a default value for all the locations. You can always override this by giving any location it's own root.
Alternatively, I could have defined root in both my locations.