Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tomcat and multiple domains/applications

Tags:

tomcat

Currently I run single tomcat with single WAR application on port 80. The domain name www.foo.org is pointed to this server ip.

What is the procedure of adding www.bar.org domain for a different client on port 80?

Thank you

like image 427
JavaSheriff Avatar asked May 22 '12 15:05

JavaSheriff


People also ask

Can we run multiple applications in Tomcat?

You can of course have multiple apps in each directory if you need. Another option is to keep the default tomcat configuration and use another http server (apache, nginx, lighttpd,...) to map a port to the internal path of a tomcat application.

What is the purpose of multiple domains?

By not owning multiple domains, you could be costing your business traffic and customers and leaving your brand vulnerable to the competition. One of the most important reasons to purchase more than one domain is to protect against user error.

Can I have 2 domains on the same IP?

It is not possible to provide two domain names for the same Server IP address and get two different SSL certificates (one for each domain name). Also note that the use of Host Headers (which is how you can use a single IP for more than one SSL enabled domain) is not recommended for E-Commerce sites.


1 Answers

From the beginning you have a single "Host" record in your conf/server.xml for localhost

<Host name="localhost"  appBase="webapps" unpackWARs="true" autoDeploy="true">       <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"                prefix="localhost_access_log." suffix=".txt"                pattern="%h %l %u %t &quot;%r&quot; %s %b" /> </Host> 

Now you can add another "Host" records, for example

  <Host name="anotherclient.com"  appBase="anotherclient" unpackWARs="true" autoDeploy="true">         <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"            prefix="anotherclient_access_log." suffix=".txt"            pattern="%h %l %u %t &quot;%r&quot; %s %b" />   </Host> 

where name="anotherclient.com" is the new client's domain, and appBase="anotherclient" is its web application root directory name (where you deploy your war); it is relative to the tomcat home dir.

Changes will be accepted after tomcat is restarted.

Requests going to any other domains (not listed in server.xml) but pointing to IP address of your server will be passed to the default application, it is specified in the Engine element

<Engine name="Catalina" defaultHost="localhost"> 
like image 159
humkins Avatar answered Oct 24 '22 19:10

humkins