想要添加动态虚拟主机和规则来代理Web请求,如下所示
subdomain1.example.com/contexta => subdomain1.appservera.internal.host
subdomain1.example.com/contextb => appserverb.internal.host
subdomain1.example.com/contextc => appserverc.internal.host
subdomain2.example.com/contexta => subdomain2.appservera.internal.host
subdomain2.example.com/contextb => appserverb.internal.host
subdomain2.example.com/contextc => appserverc.internal.host
subdomain3.example.com/contexta => subdomain3.appservera.internal.host
subdomain3.example.com/contextb => appserverb.internal.host
subdomain3.example.com/contextc => appserverc.internal.host
广义路由模式如下所示。请求将被路由到的下游服务器是从服务器名称的前缀获得的(虽然仅针对某些上下文根)。
*.example.com/contexta => *.appservera.internal.host
*.example.com/contextb => appserverb.internal.host
*.example.com/contextc => appserverc.internal.host
理想情况下,添加新子域时,我们希望Apache配置不会更改。那可能吗?
我调查Mass Virtual Hosting,但文档不清楚。
如果这不是一个简单的用例,nginx会更强大吗?
答案 0 :(得分:1)
这样的事情适用于nginx
:
server {
...
server_name "~^(?<name>.+)\.example\.com$";
...
location /contexta {
proxy_pass http://$name.appservera.internal.host/;
...
}
location /contextb {
proxy_pass http://appserverb.internal.host/;
...
}
...
}
有关详细信息,请参阅this documentation和this documentation。我相信使用Apache也很容易实现。