Creating virtual hosted apps with Apache

29 Apr 2015
by cvringer

When you develop webapps, most often you don’t want users to type in complex urls like: http://ipaddress:8080/my-webapp/, but you want to use a nice DNS url like: http://www.myserver-DOT-com/ or: http://admin.myserver-DOT-com.

So, how do you do that? It’s actually not that hard. Using Apache’s virtual host module, you can easily ‘map’ web applications to an url. Here’s how:
Software: Apache 2.2, and a servlet container

Using Apache webserver and Tomcat or Glassfish or any servlet container, this is how you do it:

First, register you DNS names! Depending on your provider, you can do this yourself. In this example, you register two domains: and It could take some time for these names to be known at all DNS servers.

In apaches conf/httpd.conf make share these lines are enabled:
LoadModule proxy_module modules/
LoadModule proxy_ajp_module modules/
LoadModule proxy_balancer_module modules/
LoadModule proxy_connect_module modules/
LoadModule proxy_http_module modules/
LoadModule rewrite_module modules/

# Virtual hosts
NameVirtualHost *:80


#Here are the .conf files of your sites)
Include conf/sites/*.conf

Create one ore more virtual host file:
Here are two examples

Restart Apache, go to and you will see the webapp. Go to, and you will see your admin console.
Thats it! you are all done.

Leave a Comment:

* - required fields

This site uses Akismet to reduce spam. Learn how your comment data is processed.

© Keienberg Consultants