VirtualHost in Tomcat (Make Tomcat a standalone web server)

Problem: I want to bind a registered domain name to my web application using Apache Tomcat as a standalone web server(means NO Apache web Server, HTTPD), simple :)
  • Windows Server (64) 2003
  • Apache Tomcat 6.0.18
  • IIS 6

Still recently what were we doing to access the web application is,
we are binding domain name "" to the IIS which is running on port 80, and then this IIS redirects the page to local instance of tomcat, which is running on port 8080, as http://localhost:8080/WebApp
So when someone hits the server redirects to the URL as
Now we need some changes into it
1.Remove port 8080 from URL (pretty easy)

Open CATLINA_HOME/conf/server.xml and search for number 8080 and replace by 80, save it and you're done. But wait, if you restarted the tomcat, it will throw exception, like ‘JVM_bind: port 80 is already in use’ and this is because of the IIS server running on that default port 80, so stop it...

2.Get the direct access to Tomcat, instead of IIS-Redirecting-Tomcat(Tomcat Virtual Host settings)

Virtual hosting is easy in a Tomcat, (though many people suggest me, to use Apache web server, HTTPD, which acts like IIS, and then redirect the request to tomcat, which I didn't understand it, yet :)),
We need some edits in following xml
Caution: Before modifying this files make sure you had backup this files, so that if anything goes wrong you need not worry about the original files.

a. Create a virtual host, which maps to the correct application deployed. Note that the <Host> element MUST be configured inside <Engine> element, see Tomcat docs for more details.

[Caution: Do NOT copy-paste the code as it is, instead edit and write into the file]

<Host name="" appbase="Mywebapps" unpackwars="true"
autodeploy="true" xmlvalidation="false" xmlnamespaceaware="false">

Here, <Host> name is the DNS registered site name “” and it will bind all the web application from folder “Mywebapps” to it
b. Create <Alias> element inside the <Host>, which takes the other format of site name and bind to the same virtual host.

<Host name="" appbase="xyzwebapps" unpackwars="true"
autodeploy="true" xmlvalidation="false" xmlnamespaceaware="false">

After this just rename your web application's war file as 'ROOT.war', so that's it context path changes from "YOUR_WEB_APP_NAME" to "/" and application can be accessed as '', simply.
So finally, this files/directory you got in 'xyzwebapps'


Restart the server, hit and you're good to go :)

PS: Here is the beautiful link to implement SSL on Tomcat, you just need a private key from your host provider. Its easy and straightforward.


eugene said…
This is a great post - easy to follow and works. Thanks.
SagaR said…
Thanks, thanks for the encouraging words. Great to knew that some one finds it useful.. and for my first "technical" post comment :)
Anonymous said…
how to add wild chatacter alias to host. exmaple "", in this 'abc' can become any thing. Is there any thing to complete this or shell we pass like '*'(its not working).
SagaR said…
First thing first - You can use wild card notations in server.xml but whether it work or not, I don't know as of now.
Second thing, do you have '' DNS entry, which is nothing but the subdomain for '' OR an appropriate entry in the C:\WINDOWS\system32\drivers\etc\hosts file for ''. Unless you got subdomain entry, you cant do as you're expecting !!
Anonymous said…
Thanks for the post.
I have a similar problem.

I'm using a VPS and I want to run a Java Web App in Tomcat in .NET app in IIS in the same server. Both have two different domain names.

Currently I can access the apps as follow.
.NET -
Java -

But i don't want to type port number in .NET app.

Pls suggest...
SagaR said…

Firstly, you can configure 2 hosts (domain) for 2 different web app dir in tomcat. See,

But, I've no knowledge how to do this in IIS.

Secondly, you need some kind of connector to delegate requests from Tomcat to IIS or vice verse.

Also, look into Apache HTTPD server, it might give you some idea.
Subbu said…
hey i registered three subdomains as follows in my original domain called


how can i bind all these three urls with my three webApplications(abc, pqr,xyz) in tomcat server.

now i configured first app, but its working with url like for first app, where for 2nd app & third app its not working properly but working like &

whats wrong with all these, am a beginner in all these.

if i change my tomcat port to 80, again prob with JVM already binded :(

please help me in details
SagaR said…
1. In order to configure 3 sub domain for same Tomcat instance, you have to add 3 element for each sub domain, like
Host name="" appbase="abcapp">

2. In order to access the web app as root app, means if you directly want to access site like, you have to create new webapp dir , like "abcapp" (see #1 point) and place ur abc.war and rename it to "ROOT.war" and start tomcat.

3. Looks like port 80 is already in use on ur server, find out which process occupied that port and kill it, then u can start tomcat on 80 port.

Popular Posts