I have the following scenario:
A single application that will serve several different domains, on a single server, and a single context of a single Tomcat instance. (The DNS of all domains are configured and functional)
That is, I need it when the browser points to the address:
domain1.example
>> redirect to >> http://127.0.0.1/websiteapp
domain2.example
>> redirect to >> http://127.0.0.1/websiteapp
domainn.com.br
>> redirect to >> http://127.0.0.1/websiteapp
In the application it is retrieved (via request URL) the calling domain, that is, it is my client identifier and through the domain I get the information in the database and return the configured views to that client.
I configured the NGINX (minimum configuration) like this:
server {
listen 80;
server_name domain1.example domain2.example domainn.com.br;
root /opt/tomcat2/webapps/websites;
location / {
proxy_pass http://127.0.0.1:8080/websitesapp;
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
Tomcat server.xml
<Context docBase="websitesapp" path="/" reloadable="true" source="org.eclipse.jst.jee.server:websitesapp"/>
In the application I retrieve the domain, and "mount" the a view with the information loaded from the database.
Is this setting correct?
Is there any way to pass the domain to tomcat more securely, ie without retrieving it by the browser's URL?
Is there any contraindication to this type of approach?
Any other approach that would be more interesting?