Reputation: 3189
Currently my Spring MVC based application runs on a root context of the domain, e.g. https://mydomain.com. In fact by default any request will be redirected to the https://mydomain.com/login. Now I would like the application to handle an additional subdomain such as https://member.mydomain.com.
My questions :
Upvotes: 1
Views: 2009
Reputation: 471
from Tomcat 7 documentation (The Host Container):
http://tomcat.apache.org/tomcat-7.0-doc/config/host.html
Introduction: The Host element represents a virtual host, which is an association of a network name for a server (such as "www.mycompany.com" with the particular server on which Tomcat is running. [...] One or more Host elements are nested inside an Engine element. Inside the Host element, you can nest Context elements for the web applications associated with this virtual host.
Common Attributes:
appBase (The Application Base directory for this virtual host. This is the pathname of a directory that may contain web applications to be deployed on this virtual host.)
name (Usually the network name of this virtual host, as registered in your Domain Name Service server.)
Usually most of users has only one host container set up within tomcat server.xml config, with a default name="localhost". Multi domain support can be achieved at Apache HTTP level, where apache pass request to tomcat through mod_jk or mod_proxy (depends on setup and sysadmin preferences). It has cons and pros. First thing is that regardless of hostname or subdomain name all requests ends up in the same place, i.e. your tomcat single host container -> application, so that your application has to detect what to serve to client. No problems if you wish to serve same content for multiple domains, but if you plan to deploy different applications for every separate domain or subdomain, Tomcat's host container configuration is what you need to do it correctly.
Upvotes: 0
Reputation: 6547
Since your webapp seems to be the only one installed in your tomcat, I assume that it would be your ROOT webapp within the tomcat. This is fine so far, all the request will be delivered to it.
For the multiple domain thing, I would suggest to use an additional webserver (e. g. Apache). That webserver will be in front of your tomcat and therefor receive all the requests. Within this apache you can create a virtual host (for mydomain.com) and several aliases (member.mydomain.com, mydomain.co.uk and so on) ...
Using Apache would allow you to do some nice stuff like request rewriting
Requests will then be forwarded to the tomcat via ajp protocol to the tomcat.
Upvotes: 3