File Not Found when running PHP with Nginx

后端 未结 15 1975
后悔当初
后悔当初 2020-12-04 13:59

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:<

15条回答
  •  醉酒成梦
    2020-12-04 14:36

    The error message “Primary script unknown or in your case is file not found.” is almost always related to a wrongly set in line SCRIPT_FILENAME in the Nginx fastcgi_param directive (Quote from https://serverfault.com/a/517327/560171).

    In my case, I use Nginx 1.17.10 and my configuration is:

        location ~ \.php$ {
          fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
          fastcgi_index index.php;
          fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
          include fastcgi_params;
          fastcgi_read_timeout 600;
        }
    

    You just change $document_root to $realpath_root, so whatever your root location, like /var/www/html/project/, you don't need write fastcgi_param SCRIPT_FILENAME /var/www/html/project$fastcgi_script_name; each time your root is changes. This configuration is more flexible. May this helps.

    =================================================================================

    For more information, if you got unix:/run/php/php7.2-fpm.sock failed (13: Permission denied) while connecting to upstream, just change in /etc/nginx/nginx.conf, from user nginx; to user www-data;.

    Because the default user and group of PHP-FPM process is www-data as can be seen in /etc/php/7.2/fpm/pool.d/www.conf file (Qoute from https://www.linuxbabe.com/ubuntu/install-nginx-latest-version-ubuntu-18-04):

    user = www-data
    group = www-data
    

    May this information gives a big help

提交回复
热议问题