Php 可选择在位置内尝试_文件
我可能需要一个简单的改变,但我已经尝试了很长时间,似乎没有任何工作Php 可选择在位置内尝试_文件,php,nginx,Php,Nginx,我可能需要一个简单的改变,但我已经尝试了很长时间,似乎没有任何工作 基本上,我想要的是try_文件,但也想要继承位置根目录 尝试将根目录替换为别名,这样它会选择/cms: server { listen 127.0.0.1:80; server_name dummy; error_log /var/logs/error.log; access_log /var/logs/access.log; send_timeout 120s; locat
基本上,我想要的是
try_文件
,但也想要继承位置根目录
尝试将根目录
替换为别名
,这样它会选择/cms
:
server {
listen 127.0.0.1:80;
server_name dummy;
error_log /var/logs/error.log;
access_log /var/logs/access.log;
send_timeout 120s;
location / {
proxy_pass http://127.0.0.1:9080;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $host;
}
# I want to serve a php application in /var/www/cmsfiles
# when the user visits http://localhost/cms/
location /cms {
root /var/www/cmsfiles;
index index.php;
error_log /var/logs/cms/errors.log;
access_log /var/logs/cms/access.log;
fastcgi_split_path_info ^(.+\.php)(.*)$;
include fastcgi_params;
fastcgi_send_timeout 120s;
fastcgi_read_timeout 500s;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
error_page 404 index.php;
fastcgi_pass unix:/run/php-fpm/php-fpm.sock;
}
}
此外,您还必须将位置/cms
分为两部分,一部分用于静态文件,另一部分用于php脚本:
location /cms {
alias /var/www/cmsfiles;
...
奇怪的是,将其更改为
alias
并不能解决此问题,它仍然在/var/www/cmsfiles/cms
下查找文件$fastcgi\u script\u name
似乎仍然解析为/cms/index.php
您确定要将fastcgi\u param script\u FILENAME
设置为正确的值吗?
location /cms {
alias /var/www/cmsfiles;
index index.php;
access_log ...
location ~ \.php$ {
fastcgi ...
}
}