What I am trying to achieve
The web application should be able to support multiple subdomains without having to make any changes on the nginx or tomcat every time a new subdomain is used. (I have already done the required changes to DNS to support wild card subdomains)
Nginx listens to port 80. It does a proxy_pass to tomcat at port 8080. nginx should be able to support multiple subdomain.
My current setup is based on this answer. But it is not passing the parameter
Nginx proxy_pass : Is it possible to add a static parameter to the URL?
Every possible subdomain
dynamic_subdomain_1.localhost
dynamic_subdomain_2.localhost
nginx setup
server {
listen 80 default_server;
server_name ~^(?<subdomain>.+)\.localhost$;
location / {
set $args ?$args&site=$subdomain;
proxy_pass http://127.0.0.1:8080;
}
}
Nginx should append the subdomain as a parameter when it invokes Tomcat.
The Calls to Tomcat should be as follows for each subdomain
http://127.0.0.1:8080?site=dynamic_subdomain_1
http://127.0.0.1:8080?site=dynamic_subdomain_2
I have tried the above setup but the query parameter always shows up as null.
What should I change in nginx to make this possible?