我尝试只为一个子目录(laravel 目录)启用 PHP,但我没有设法让它工作。NGINX 总是说 404 File not found 或 php 说“没有指定输入文件”。我究竟做错了什么?
这是我的位置配置:
location /laravel {
root html/laravel/public;
index index.php index.html index.html;
try_files $uri $uri/ /index.php?$query_string;
location ~ \.php$ {
root html/laravel/public;
fastcgi_pass 127.0.0.1:9000;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME document_root$fastcgi_script_name;
#include fastcgi_params;
include fastcgi.conf;
}
}
UDPATE 1:似乎 nginx 没有正确评估我的位置表达式:
2018/09/12 16:30:44 [error] 26476#24408: *1 CreateFile() "C:/Server/nginx/html/index.php" 失败(2:系统找不到指定的文件),客户端:127.0.0.1,服务器:localhost,请求:“GET /laravel/ HTTP/1.1”,主机:“localhost”
这是错误的路径,至少是 / 位置的根:
location / {
root C:/Server/nginx/html;
index index.html index.htm index.php;
}
我试图移动块但没有任何变化。
更新 2:似乎 nginx 非常有问题。该文档指出:
按指定顺序检查文件是否存在,并使用第一个找到的文件进行请求处理;处理在当前上下文中执行。文件的路径是根据根和别名指令从文件参数构造的。可以通过在名称末尾指定斜杠来检查目录是否存在,例如“$uri/”。如果没有找到任何文件,则内部重定向到最后一个参数中指定的 uri。
正如我的错误日志所示,try_files 指令不尊重根路径,因为它试图打开相对于另一个位置块的文件。