Proxy Apache Tomcat behind Apache2 Web Server - Amazon EC2

I installed Apache Tomcat and Apache Web Server on my Amazon EC2 instance recently.

On a Amazon EC2 instance you typically restrict HTTP access via port 80. Apache Tomcat default port is 8080.

I had a requirement to access the Apache Tomcat management console through a HTTP connection. To achieve this you need to proxy the Apache Web Server to the Tomcat instance.


The following instructions were done on a Ubuntu 12.04 instance.

First enable the Apache mod_proxy module ( if not already enabled )

sudo a2enmod proxy_http

To install the module you need to restart apache2 web server.

sudo /etc/init.d/apache2 restart


You now need to identify to Apache the sites that are available for the proxy. So, you create a file ( your choice of name ) within the sites-available folder.


/etc/apache2/sites-available$ sudo nano tomcat-app_proxy


The following goes in the file.


<Proxy *>
   Order deny,allow
   Allow from all
</Proxy>
ProxyRequests Off
ProxyPreserveHost On
ProxyPass / http://localhost:8080/
ProxyPassReverse / http://localhost:8080/





Now you need to apply the configuration to Apache2


/etc/apache2/sites-available$ sudo a2ensite

This will ask you a question about which file has the configuration. In my example I entered tomcat-app_proxy

Now just restart Apache Web Server


/etc/apache2/sites-available$ /etc/init.d/apache2 restart

From your local browser you should be able to access the Tomcat Management console. You will have something like:

http://<your amazon ec2 domain or IP address>



Comments

  1. You may think you could just expose port 8080 from the EC2 instance. I don't think that's a good idea.

    Keep the number of open ports on your EC2 instance as small as possible. Safer...

    ReplyDelete

Post a Comment

Popular posts from this blog

Vaadin - GRID Component

Connecting a Vaadin SQL Container to a Combo Box

Vaadin and Google Maps