File Not Found when running PHP with Nginx

2020-02-02 05:03发布

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

标签: php nginx
12条回答
Ridiculous、
2楼-- · 2020-02-02 05:21

When getting "File not found", my problem was that there was no symlink in the folder where was pointing this line in ngix config:

root /var/www/claims/web;
查看更多
爷的心禁止访问
3楼-- · 2020-02-02 05:26

Probably it's too late to answer but a couple things since this is a really annoying error. Following solution worked on Mac OS X Yosemite.

  1. It's the best if you have

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

  1. The include with fast cgi params should go above that line.

  2. All your directories down to the PHP file you're executing (including that file too) should have a+x permissions, e.g.

sudo chmod a+x /Users/
sudo chmod a+x /Users/oleg/
sudo chmod a+x /Users/oleg/www/
sudo chmod a+x /Users/oleg/www/a.php
查看更多
4楼-- · 2020-02-02 05:27

I had this error as well. In my case it was because there was another virtual host that was pointing to the same root directory.

查看更多
够拽才男人
5楼-- · 2020-02-02 05:31

In my case, it was because the permissions on the root web directory were not set correctly. To do this, you need to be in the parent folder when you run this in terminal:

sudo chmod -R 755 htmlfoldername

This will chmod all files in your html folder, which is not recommended for production for security reasons, but should let you see the files in that folder, to be sure that isn't the issue while troubleshooting.

查看更多
Fickle 薄情
6楼-- · 2020-02-02 05:32

I just spent like 40 minutes trying to debug a non-working /status with:

$ SCRIPT_NAME=/status SCRIPT_FILENAME=/status QUERY_STRING= REQUEST_METHOD=GET cgi-fcgi -bind -connect /var/run/php5-fpm.sock

It just produced "File not found" error, while the actual scripts (that are found on the filesystem) worked just fine.

Turned out, I had a couple of orphaned processes of php5-fpm. After I killed everything and restarted php5-fpm cleanly, it just went back to normal.

Hope this helps.

查看更多
forever°为你锁心
7楼-- · 2020-02-02 05:32

After upgrading to PHP72, we had an issue where the php-fpm.d/www.conf lost the settings for user/group which was causing this error. Be sure to double check those if your setup involves php-fpm.

查看更多
登录 后发表回答