gpt4 book ai didi

nginx - 在子域上使用具有不同根文件夹的多个位置配置 nginx

转载 作者:行者123 更新时间:2023-12-03 04:13:01 25 4
gpt4 key购买 nike

我希望将子域的根 URL 和子域的目录提供给我的服务器上的两个不同文件夹。这是我的简单设置,但不起作用......

server {

index index.html index.htm;
server_name test.example.com;

location / {
root /web/test.example.com/www;
}

location /static {
root /web/test.example.com/static;
}
}

在此示例中,访问 test.example.com/ 会将索引文件引入 /web/test.example.com/www

并且转到test.example.com/static会将索引文件引入/web/test.example.com/static

最佳答案

您需要对 location/static 使用 alias 指令:

server {

index index.html;
server_name test.example.com;

root /web/test.example.com/www;

location /static/ {
alias /web/test.example.com/static/;
}

}

nginx wiki比我更好地解释了根和别名之间的区别:

Note that it may look similar to the root directive at first sight, but the document root doesn't change, just the file system path used for the request. The location part of the request is dropped in the request Nginx issues.

请注意,rootalias 处理尾部斜杠的方式不同。

关于nginx - 在子域上使用具有不同根文件夹的多个位置配置 nginx,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11570321/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com