Ideas and Code

domenica 2 agosto 2009

Virtual Hosts with Apache, Tomcat, AJP

Here I describe how to configure Apache to handle request for 2 virtual hosts, redirecting the requests to 2 Tomcat installed on the same machine.

Suppose you want to handle 2 applications hello.com and welcome.com.
The DNS points to the same IP address and Apache is listening to port 80.


Apache/2.2.3

Add proxy_ajp.conf in /etc/httpd/conf.d

LoadModule proxy_ajp_module modules/mod_proxy_ajp.so

NameVirtualHost *

<VirtualHost *>
ServerName hello.com
DocumentRoot /var/local/tomcat/webapps/ROOT/
ProxyPass /static/ !
ProxyPass / ajp://localhost:8091/
ProxyPassReverse / ajp://localhost:8091/
</VirtualHost>

<VirtualHost *>
ServerName welcome.com
DocumentRoot /var/local/tomcat2/webapps/ROOT/
ProxyPass /static/ !
ProxyPass / ajp://localhost:8090/
ProxyPassReverse / ajp://localhost:8090/
</VirtualHost>


Note how the static files (tipically images, css, javascripts... everything inside /static/) will be served by Apache. You need to have both "ProxyPass /static/ !" and the correct DocumentRoot.

Tomcat 6.0.18

The default configuration of Tomcat 6.0.18 works pretty fine. You just have to change the ports so they don't conflict. I'm using 8090 and 8091 for the 2 APJ Connectors of the 2 Tomcats.

Nessun commento:

Posta un commento