Apache – Tomcat – PROXY PASS


Steps for proxy a request to SimpleServlet.com


hosts file:

$ nano /etc/hosts
127.0.0.1 SimpleServlet.com


Tomcat changes:

on my deploy, the webapps directory is: :/var/lib/tomcat6/webapps

$ nano /etc/tomcat6/server.xml

#### Inside of the <Engine> tag add below:
<!– SimpleServlet.com –>
<Host
name="SimpleServlet.com"
appBase="webapps/SimpleServlet"
unpackWARs="true"
autoDeploy="true">

<Context
path=""
docBase=""
debug="1"
reloadable="true"/>

<Valve
className="org.apache.catalina.valves.AccessLogValve"
directory="logs"
prefix="tomcat_access_"
suffix=".log"
pattern="common"
resolveHosts="false"/>
</Host>

#### After the </Engine> tag add the below.
#### Each Virtual Host Proxy must be on a different port, remember this for your SimpleServlet.com Apache2 entry
<Connector port="9282" proxyPort="80" proxyName="SimpleServlet.com"/>


Apache2:

$ sudo a2enmod proxy
$ sudo a2enmod proxy_http

$ cd /etc/apache2/sites-available
$ nano SimpleServlet.com

<VirtualHost *:80>

ServerName SimpleServlet.com

<IfModule mod_proxy.c>
ProxyRequests Off

<Proxy SimpleServlet.com>
Order deny,allow
Deny from all
Allow from all
</Proxy>

ProxyPass /index.html !
ProxyPass /sitemap.xml !
ProxyPass / http://SimpleServlet.com:9282/
ProxyPassReverse / http://SimpleServlet.com/

</IfModule>

</VirtualHost>


Restart All:

$ /etc/init.d/apache2 reload

$ a2ensite SimpleServlet.com
$ sudo /etc/init.d/tomcat6 restart
$ /etc/init.d/apache2 restart


Tag Cloud