nginx如何为特定的根文件夹提供“admin”子域请求?

时间:2016-02-06 11:13:25

标签: nginx

是否可以向example.com(和www.example.co)提供所有请求 从根文件夹

location / {
        root   html;
        index  index.html index.htm;
}

但所有来自同一服务器上另一个文件夹“admin”的admin.example.com请求?

2 个答案:

答案 0 :(得分:0)

admin.example.com应该在nginx配置中配置为单独的server,但没有人限制您将其根目录指向其他服务器的根目录

server {
  listen 80;
  server_name admin.example.com;
  root /some/path/example.com/admin;

  location / {
    index index.html;
  }
}

server {
  listen 80;
  server_name www.example.com example.com;
  root /some/path/example.com;
  location / {
    index index.html index.htm;
  }
}

答案 1 :(得分:0)

使用不同的服务器指令,这样:

server {
    server_name admin.example.com;

    root   admin;

    location / {
        index  index.html index.htm;
    }

}

server {
    server_name example.com;

    root   html;

    location / {
        index  index.html index.htm;
    }
}

此外,最好在服务器级别只使用一个root指令,而不是在location块中重复它(cf pitfalls)。