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: www.myserver.com and admin.myserver.com. 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/mod_proxy.so
LoadModule proxy_ajp_module modules/mod_proxy_ajp.so
LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
LoadModule proxy_connect_module modules/mod_proxy_connect.so
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule rewrite_module modules/mod_rewrite.so
# Virtual hosts
#Here are the .conf files of your sites)
Create one ore more virtual host file:
Here are two examples
Restart Apache, go to http://helloworld.com/ and you will see the webapp. Go to http://admin.helloworld.com/, and you will see your admin console.
Thats it! you are all done.