【发布时间】:2014-05-11 09:08:02
【问题描述】:
我正在努力实现的目标
Web 应用程序应该能够支持多个子域,而无需在每次使用新子域时对 nginx 或 tomcat 进行任何更改。 (我已经对 DNS 进行了必要的更改以支持通配符子域)
Nginx 监听 80 端口。它在 8080 端口对 tomcat 执行 proxy_pass。 nginx应该能够支持多个子域。
我目前的设置是基于这个答案。但它没有传递参数
Nginx proxy_pass : Is it possible to add a static parameter to the URL?
所有可能的子域
dynamic_subdomain_1.localhost
dynamic_subdomain_2.localhost
nginx 设置
server {
listen 80 default_server;
server_name ~^(?<subdomain>.+)\.localhost$;
location / {
set $args ?$args&site=$subdomain;
proxy_pass http://127.0.0.1:8080;
}
}
Nginx 在调用 Tomcat 时应将子域作为参数附加。
每个子域对 Tomcat 的调用应如下所示
http://127.0.0.1:8080?site=dynamic_subdomain_1
http://127.0.0.1:8080?site=dynamic_subdomain_2
我已经尝试了上面的设置,但是查询参数总是显示为空。
我应该在 nginx 中进行哪些更改才能实现这一点?
【问题讨论】:
标签: java tomcat nginx dns wildcard-subdomain