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

2024-02-05

我希望将子域的根 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


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

server {

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

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

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

}

The Nginx 维基 http://wiki.nginx.org/HttpCoreModule#alias比我更好地解释了根和别名之间的区别:

请注意,乍一看它可能与 root 指令类似,但文档根并没有改变,只是用于请求的文件系统路径。请求的位置部分在 Nginx 发出的请求中被删除。

注意root and alias以不同方式处理尾部斜杠。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

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

随机推荐