Suppose you have your web app hosted by Tomcat at http://localhost:8080/myapp. That’s an ugly address for end users, so you want it to be accessible as http://somesystem.example.com. Here’s how you can do it with a little help from Apache via mod_proxy and mod_rewrite.
- Install Apache:
- Enable optional modules:
- Configure proxy (/etc/apache2/httpd.conf):
- Configure virtual host (/etc/apache2/sites-available/somesystem):
- Enable virtual host:
- Restart Apache:
- Enable proxy support in Tomcat (conf/server.xml):
- Restart Tomcat
apt-get install apache2
a2enmod proxy a2enmod proxy_http a2enmod rewrite
ProxyRequests Off <Proxy *> Order deny,allow Allow from all </Proxy>
<VirtualHost *>
ServerName somesystem.example.com
RewriteEngine On
ProxyPass / http://localhost:8080/myapp
ProxyPassReverse / http://localhost:8080/myapp
</VirtualHost>
a2ensite somesystem
/etc/init.d/apache2 restart
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" proxyPort="80" />
Note: It’s written for Ubuntu, but can be easily converted to other systems.