Multiple Virtual Hosts (1 x Apache httpd + 2 x Apache Tomcat)
joaocunhalopes Feb 13, 2015 7:29 AMHi all.
Questions are on the end of this post.
Scenario definitions:
windows 32 bit
mod_cluster 1.2.6 Final
1 x Apache httpd 2.2 (configuration with 1 main server + 1 virtual host for mod_cluster + 2 virtual hosts for dynamic content + 1 virtual host for direct IP requests)
2 x Apache Tomcat 6
On the httpd side:
# Modules for JBoss mod_cluster
LoadModule proxy_ajp_module modules/mod_proxy_ajp.so
LoadModule slotmem_module modules/mod_cluster/mod_slotmem.so
LoadModule manager_module modules/mod_cluster/mod_manager.so
LoadModule proxy_cluster_module modules/mod_cluster/mod_proxy_cluster.so
LoadModule advertise_module modules/mod_cluster/mod_advertise.so
# mod_manager (mod_cluster) configuration.
<IfModule manager_module>
Maxnode 60
Maxhost 40
Maxcontext 200
</IfModule>
# mod_proxy_cluster (mod_cluster) configuration.
<IfModule proxy_cluster_module>
CreateBalancers 1
</IfModule>
# Bind Apache to IP address 192.168.125.108 and port 6666.
Listen 192.168.125.108:6666
# Virtual host for JBoss mod_cluster (port 6666 will be used to receive information from Tomcat servers)
<VirtualHost 192.168.125.108:6666>
KeepAliveTimeout 60
MaxKeepAliveRequests 0
ServerAdvertise Off
EnableMCPMReceive
<Location />
Order deny,allow
Deny from all
Allow from 192.168.125.
</Location>
</VirtualHost>
# www.server1.com
<VirtualHost *:80>
# Named server information
ServerAdmin "someone at somewhere dot com"
ServerName www.server1.com
# Log files
ErrorLog "|bin/rotatelogs -l logs/www.server1.com-error_%Y%m%d.log 86400"
CustomLog "|bin/rotatelogs -l logs/www.server1.com-access_%Y%m%d.log 86400" combined
# Enables runtime rewriting engine
RewriteEngine on
# Exceptions to mod_cluster balancer.
ProxyPass / balancer://aaaa/ stickysession=JSESSIONID|jsessionid nofailover=On
ProxyPassReverse / balancer://aaaa/
ProxyPreserveHost on
</VirtualHost>
# www.server2.com
<VirtualHost *:80>
# Named server information
ServerAdmin "someone at somewhere dot com"
ServerName www.server2.com
# Log files
ErrorLog "|bin/rotatelogs -l logs/www.server2.com-error_%Y%m%d.log 86400"
CustomLog "|bin/rotatelogs -l logs/www.server2.com-access_%Y%m%d.log 86400" combined
# Enables runtime rewriting engine
RewriteEngine on
# Exceptions to mod_cluster balancer.
ProxyPass / balancer://bbbb/ stickysession=JSESSIONID|jsessionid nofailover=On
ProxyPassReverse / balancer://bbbb/
ProxyPreserveHost on
</VirtualHost>
# 192.168.125.108 (Named server for internal service. No HTTPS)
<VirtualHost *:80>
# Named server information
ServerAdmin "someone at somewhere dot com"
ServerName 192.168.125.108
# Log files
ErrorLog "|bin/rotatelogs -l logs/192.168.125.108-error_%Y%m%d.log 86400"
CustomLog "|bin/rotatelogs -l logs/192.168.125.108-access_%Y%m%d.log 86400" combined
# mod_cluster Manager
<Location /mcm>
SetHandler mod_cluster-manager
Order deny,allow
Deny from all
Allow from 192.168.125.
</Location>
</VirtualHost>
On the tomcat(#1) side:
<Listener className="org.jboss.modcluster.container.catalina.standalone.ModClusterListener" advertise="false" proxyList="192.168.125.108:6666" excludedContexts="ROOT,manager" balancer="aaaa" stickySession="true" stickySessionForce="false" stickySessionRemove="true"/>
On the tomcat(#2) side:
<Listener className="org.jboss.modcluster.container.catalina.standalone.ModClusterListener" advertise="false" proxyList="192.168.125.108:6666" excludedContexts="ROOT,manager" balancer="bbbb" stickySession="true" stickySessionForce="false" stickySessionRemove="true"/>
And the questions:
Question 1. The above works, and it's possible to get tomcat(#1) contexts loaded on virtual host www.server1.com since it's using balancer aaaa. Now, the interesting part is that CreateBalancers 1 does not seem to make a difference. In other words, commenting the lines
# mod_proxy_cluster (mod_cluster) configuration.
#<IfModule proxy_cluster_module>
# CreateBalancers 1
#</IfModule>
does not seem to make a difference.
According to the manual for CreateBalancers
0: Create in all VirtualHosts defined in httpd.
2: Create only the main server.
So, removing any explicit configuration should set the default value of 2, thus creating only the main server.
It should be noticed that on the main server I am not using the line
ManagerBalancerName cttcluster
Actually I am not using ManagerBalancerName anywhare in this config.
Nevertheless, it all works as if CreateBalancers 1 or CreateBalancers 2 (defualt) was exactly the same configuration. My expectations would be otherwise.
Any thoughts on this?
Question 2. Considering that tomcat#1 had context helloworld1 and that tomcat#2 has contexts helloworld1 *and* helloworld2, i.e.
tomcat#1 reports to httpd on balancer aaaa context helloworld1
tomcat#2 reports to httpd on balancer bbbb context helloworld1 *and* context helloworld2
The following is loading *all* bbbb contexts (helloworld1 *and* helloworld2) on virtual host www.server2.com, while I would expect it to load only helloworld2
# www.server2.com
<VirtualHost *:80>
# Named server information
ServerAdmin "someone at somewhere dot com"
ServerName www.server2.com
# Log files
ErrorLog "|bin/rotatelogs -l logs/www.server2.com-error_%Y%m%d.log 86400"
CustomLog "|bin/rotatelogs -l logs/www.server2.com-access_%Y%m%d.log 86400" combined
# Enables runtime rewriting engine
RewriteEngine on
# Exceptions to mod_cluster balancer.
ProxyPass / balancer://bbbb/helloworld2/ stickysession=JSESSIONID|jsessionid nofailover=On
ProxyPassReverse / balancer://bbbb/helloworld2/
ProxyPreserveHost on
</VirtualHost>
I can explicity exclude dinamic content
ProxyPassMatch ^/helloworld1/(.*)$ !
ProxyPass / balancer://bbbb/ stickysession=JSESSIONID|jsessionid nofailover=On
ProxyPassReverse / balancer://bbbb/
But my expectation is that it would not be necessary in the first place (due to loading only balancer://bbbb/helloworld2
Any comments?
Thank you.