February 21, 2010

Configure Apache Web Server as Reverse Proxy in front of a Tomcat or J2EE Container

One production like scenario when using SSL or load balancing is to use a Apache Web Server in front of a Java Web Container or J2EE Container. There are two ways to make the Apache Web Server and the behind Java container – mod_proxy or mod_jk. In this blog I will show you how to use the mod_proxy alternative, acting as a reverse proxy. I will also use Ubuntu to show you how easy there is to install software on Ubuntu with Synaptic Package Manager.

The first thing to do is to install Apache Web Server and the Tomcat Container.



After installing the above software you can use the apache2ctl command to view the active sites configuration



or you can also list the files in /etc/apache2/sites-enabled



Before continue you can also check that everything is working by open a web browser and open http://localhost/ (Apache Web Server) and http://localhost:8080/ (Tomcat)

Now we go ahead and creating a new virtual host that is going to act as reverse proxy.





After creating the new site we need to link it from sites-enabled, either use ln -s or you can use the apache tool – a2ensite.



With the configuration in place, you need to separate the virtual host in customapp and default. For a locale environment you can separate them by using different IP – 127.0.0.1 and your computer IP.



The last thing before restarting the Apache Web Server is to install proxy and proxy_http modules you can do that with the Apache tool a2enmod



And finally you need to restart the Apache Web Server.

2 comments:

hip0 said...

I'm quite new to J2EE and proxying and a Debian user and thanks to your article its a bit more clear in my head ...

Adil BEN said...

For other people who do not know what that means reverse proxy I share with them this post what is reverse proxy