Nginx错误:"Primary script unknown ",我该如何解决?谢谢



Config :

  • macOS 莫哈韦

  • Debian 9.9.0 64位在虚拟盒子 6.0.8 上,在端口 192.168.56.50 上

  • Debian 上的 PHP FPM 7.2

  • nginx/稳定版,现在 1.16.0-1~在 Debian 上扩展

Nginx和php fpm将www-data作为用户。 目录 :

  • lrwxrwxrwx www-data www-data/var/www/all ->/media/sf_web

  • drwxrwx--- www-data www-data/var/www

Config 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 根 vboxsf temp_converter
  • Drwxrwx--- 1 根 vboxsf myproject

我想使用 Firefox(或其他网络浏览器)在/media/sf_web 下显示项目文件夹,但它不起作用。 当我尝试在此IP上连接时,nginx显示"找不到文件",并且在错误日志中我看到"主脚本未知"。

E.J :

  • http://192.168.56.50

  • http://192.168.56.50/myproject/index.php

你还没有设置全局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;
}

最新更新