1 FastCGI sent in stderr: “Primary script unknown”

前端 未结 5 1654
有刺的猬
有刺的猬 2021-02-04 05:15

My first time using Nginx, but I am more than familiar with Apache and Linux. I am using an existing project and when ever I am trying to see the index.php I get a 404 File not

5条回答
  •  有刺的猬
    2021-02-04 05:56

    "Primary script unknown" is caused by SELinux security context.

    client get the response

    File not found.

    nginx error.log has the following error message

    *19 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream

    so just change security context type of web root folder to httpd_sys_content_t

    chcon -R -t httpd_sys_content_t /var/www/show




    there are 3 users for nginx/php-fpm config

    /etc/nginx/nginx.conf

    user nobody nobody;  ### `user-1`, this is the user run nginx woker process
    ...
    include servers/*.conf;
    

    /etc/nginx/servers/www.conf

    location ~ \.php$ {
    #   fastcgi_pass 127.0.0.1:9000;  # tcp socket
        fastcgi_pass unix:/var/run/php-fpm/fpm-www.sock;  # unix socket
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
    

    /etc/php-fpm.d/www.conf

    [www]
    user = apache  ### `user-2`, this is the user run php-fpm pool process
    user = apache
    
    ;listen = 127.0.0.1:9000  # tcp socket
    listen = /var/run/php-fpm/fpm-www.sock  # unix socket
    
    listen.onwer = nobody  ### `user-3`, this is the user for unix socket, like /var/run/php-fpm/fpm-www.sock
    listen.group = nobody  # for tcp socket, these lines can be commented
    listen.mode = 0660
    

    user-1 and user-2 is not necessary to be the same.

    for unix socket, user-1 need to be the same as user-3, as nginx fastcgi_pass must have read/write permission on the unix socket.

    otherwise nginx will get 502 Bad Gateway, and nginx error.log has the following error message

    *36 connect() to unix:/var/run/php-fpm/fpm-www.sock failed (13: Permission denied) while connecting to upstream

提交回复
热议问题