1 FastCGI sent in stderr: “Primary script unknown”

前端 未结 5 1655
有刺的猬
有刺的猬 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:35

    I dont know how the $document_root is calculated but I resolved the issue , by really making sure that my document root is at /usr/share/nginx/ just wher the html folder exist

    0 讨论(0)
  • 2021-02-04 05:49

    Ok, so 3 things I found after a day of struggling

    1. For some reason I had already something running on port 9000 so I changed to 9001
    2. My default site was intercepting my new one, once again I don't under stand why since it shouldn't, but I just unlinked it
    3. Nginx doesn't automatically do the sym link for sites-available to site-enabled.

    Hope this saves someone some trouble!

    Here is a more detailed link in server fault: https://serverfault.com/questions/517190/nginx-1-fastcgi-sent-in-stderr-primary-script-unknown/517207#517207

    0 讨论(0)
  • 2021-02-04 05:53

    That message from the fastcgi server usually means that the SCRIPT_FILENAME that it was given was not found or inaccessible as a file on its filesystem.

    Checkout file permissions on /home/willem/git/console/frontend/www/index.php

    Is it 644?

    And /home/willem/git/console/frontend/www/

    Is it 755?

    0 讨论(0)
  • 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

    0 讨论(0)
  • 2021-02-04 05:59

    In case anyone had the same error: in my case the problem was the missing root directive inside the location block in nginx.conf, as explained in the Arch wiki

    0 讨论(0)
提交回复
热议问题