我正在尝试将一个应用程序从apache服务器移动到nginx。问题是子目录中有多个应用程序,我找不到配置服务器的正确方法。
我需要什么:
-
www.example.com
从服务
/srv/app
-
www.example.com/sub1
从服务
/srv/app/sub1
-
www.example.com/sub2
从服务
/srv/app/sub2
每个应用程序都需要相同的配置,因此我在一个片段中提取了该配置:
# snippets/app.conf
index index.php index.html index.htm index.nginx-debian.html;
location /system {
return 403;
}
# [a couple of other 403s excluded]
# Pass non-file URI to index.php
location / {
try_files $uri $uri/ /index.php?$query_string;
}
# Use PHP
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
}
# Hide .htaccess
location ~ /\.ht {
deny all;
}
在主服务器文件中:
# [non-www and http redirects]
server {
# [listen directives]
server_name www.example.com;
root /srv/app;
include snippets/app.conf;
location /sub1 {
root /srv/app/sub1;
include snippets/app.conf;
}
# [other sub-apps included in the same way]
# [ssl stuff]
}
但是,这给了我一个错误:
nginx:[emerg]location“/system”在外部location“/sub1”in/etc/nginx/snippets/app.conf:5
从错误中可以明显看出
/system
被解释为“绝对的”
www.example.com/system
而不是嵌套的
www.example.com/sub1/system
. 我是否可以指定要将嵌套位置视为相对位置?或者我只需要为每个改变前缀的子应用重复几乎相同的配置?