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;
}
}
我可能需要在这里进行简单的更改,但我已经尝试了很长时间,似乎没有任何工作。
基本上我想要的是try_files
,但也希望继承位置root
。
答案 0 :(得分:0)
尝试将root
替换为alias
,以便扼杀/cms
:
location /cms {
alias /var/www/cmsfiles;
...
此外,您必须将位置/cms
拆分为两个,一个用于静态文件,一个用于PHP脚本:
location /cms {
alias /var/www/cmsfiles;
index index.php;
access_log ...
location ~ \.php$ {
fastcgi ...
}
}