server 配置如下
server { listen 80; server_name localhost; root /data/wwwroot/public; location / { # root /data/wwwroot/public; index index.html index.htm index.php; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } if (!-e $request_filename) { rewrite ^(.*)$ /index.php$1 last; } location ~ \.php(.*)$ { # root /data/wwwroot/public; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_split_path_info ^((?U).+\.php)(/?.+)$; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info; include fastcgi_params; } }
问题是
1、把 root 放到 Localtion 中,同时注释掉 server 中的 root ,请求得到的实际路径是
/usr/local/nginx/html/
2、应用1操作,同时把 location ~ .php(.*)$ 中 root 启用,实际请求会是
/data/wwwroot/public/index.php/index.php
多了个 index.php 出来,不知道是哪里触发的
3、尝试修改 fastcgi_param SCRIPT_FILENAME 为项目实际路径也无效果 !
- 没记错的话,
location
里应该用alias
,原因忘记了 - 看你的配置,似乎少了
try_files $uri $uri/ /index.php$args;
,没有先尝试直接命中的文件。不确定是不是这个原因。 - 有没有效果不是试出来的,你得先找到
SCRIPT_FILENAME
的生效原因,改它才有意义 - 2023 年了,还在用 9000 啊……可以升级到 php-fpm 了