When nginx+ PHP is deployed, the test page appearsFile not found.View the nginx error log displayFastCGI sent in stderr: "Primary script unknown" while reading response header from upstream

  • solution

    Determining configuration ParametersSCRIPT_FILENAMEIs accessible, such as

    location ~ \.php$ {
        root           /home/web;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $fastcgi_script_name;
        fastcgi_param   SCRIPT_NAME     $fastcgi_script_name;
        include        fastcgi_params;
    }
    Copy the code

    Need to

    location ~ \.php$ { root /usr/local/var/www/lara/public; Fastcgi_pass 127.0.0.1:9000; # set the default nginx home file fastcgi_index index.php; Fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name fastcgi_param SCRIPT_NAME $document_root$fastcgi_script_name; include fastcgi_params; }Copy the code

    Ensure that nginx and PHP-fPM have the same user and user group permissions

    The simplest way to do this is to check the php-fpm www.conf and nginx nginx.conf file permissions, obtain the corresponding user and user group, and fill in. If nginx does not restart after this step, you will see an error similar to mine in the error log: Getgrnam (” wangshimin “) failed in/usr/local/etc/nginx/nginx. Conf: 2 it is important to note that there is a pit can be learned by manual

    User Syntax: user user [group] Default value: If the main process is running as root, Nginx will call setuid()/setgid() to set the user/group. If nogroup is specified, the same group as the user is used. By default, user nobody and group nobody (or nogroup) are used. Or --user= user and --group= group values specified at compile time. user www users;Copy the code

In nginx.conf, if the user group is not specified, the group name will be the same as the user name by default. Therefore, error. The solution is to complete the user group. Here I’m using admin, so my configuration items are as follows: www.conf file

user = wangshimin
group = admin
Copy the code

Nginx. Conf file

user  wangshimin admin;
Copy the code

Then restart nginx, still an error nginx: [emerg] unknown log format “main” in ~ / usr/local/etc/nginx/nginx. Conf: 35

http { ... Log_format main '$remote_addr - $remote_user [$time_local] "$request" "$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; Access_log /access.log main; access_log /access.log main; . }Copy the code

Here the log_format above are removed comments to restart again nginx, found that there is an error nginx: [error] open () “/ usr/local/Cellar/nginx / 1.21.3 / logs/nginx pid” failed (2: No such file or directory) Each person’s environment is different, the reason why I error here is because there is No such file in this directory, but found this file in another directory, so modify (reference can be).

pid        /usr/local/var/run/nginx.pid;
Copy the code

Don’t forget sudo nginx-s reload!