Nginx error : "Primary script unknown ", how can I resolve that ? Thank you

Nginx error : "Primary script unknown ", how can I resolve that ? Thank you

配置:

Nginx 和 phpfpm 拥有 www-data 作为用户。 目录:

配置 nginx : /etc/nginx/conf.d/default.conf

server {
    listen   80;
    server_name _;
    charset utf-8;

    location / {
       root /var/www/all/;
       try_files $uri /index.html index.php;
       }

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    location ~ \.php$ {
     include /etc/nginx/fastcgi_params;
      fastcgi_index index.php;
      fastcgi_split_path_info ^(.+\.php)(/.+)$;
       fastcgi_pass unix:/run/php/php7.2-fpm.sock;
     fastcgi_param   SCRIPT_FILENAME $document_root$fastcgi_script_name;

    }

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    location ~ /\.ht {
        deny  all;
    }
}

当我执行此命令时: sudo ls -l /var/www/all/ ,我得到:

  • drwxrwx--- 1 root vboxsf temp_converter
  • drwxrwx--- 1 root vboxsf myproject

我想使用 Firefox(或其他网络浏览器)显示 /media/sf_web 下的项目文件夹,但它不起作用。 当我尝试连接到这个 ip 时,nginx 显示 "File not found" 并且在错误日志中我看到 "Primary script unknow".

e.j :

你没有设置全局root语句,所以Nginx会在默认根目录下寻找PHP个文件。您需要将 root 语句从 location / 块内移动到 server 块范围内。

try_files 的说法是完全错误的。

尝试:

root /var/www/all/;

location / {
    try_files $uri $uri/ /index.php;
}
...
location ~ \.php$ {
    try_files $uri =404;

    include /etc/nginx/fastcgi_params;
    fastcgi_pass unix:/run/php/php7.2-fpm.sock;
    fastcgi_param  SCRIPT_FILENAME $request_filename;
}