How to host multiple sites at Tomcat?
Is it possible to host multiple sites with Tomcat? Each site has to have its own domain name and "/"
context. I failed to fi开发者_StackOverflow中文版nd any documentation/instructions about this.
Definitely possible, and very easy. The Tomcat master configuration file conf/server.xml can contain multiple elements, each of which contains their own settings and webapp definitions. Tomcat will match incoming requests against these hosts (host aliases are also supported) and forward the request to the correct webapp.
So, typically you would add a declaration with a host-specific app-base directory, then drop a WAR into that directory and it would work.
See The Host Container for specific host configuration.
Yet even another possibility would be to use tomcat as a dispatcher/proxy server for another applications in different tomcats or in the same.
To accomplish this it would recommend you to use the UrlRewriteFilter
Create a new web project named ROOT, integrate the UrlRewriteFilter and deploy it in your tomcat.(Download the libraries commons-codec and commons-httpclient if you are going to use it as proxy)
Edit the urlrewrite.xml and design your routing there.
<rule>
<condition name="host" operator="equal">mydomain1.com</condition>
<from>(.*)</from>
<to type="proxy">http://localhost:8080/MyDomain1/index.jsp?$1</to>
</rule>
<rule>
<condition name="host" operator="equal">mydomain2.com</condition>
<from>(.*)</from>
<to type="proxy">http://localhost:8090/MyDomain2/index.jsp?$1</to>
</rule>
*Mind the "to type" according to your needs more info.
*This filter is very helpful to create SEO friendly urls.
精彩评论