apache proxypassreverse ServerName not working
I have a secondary development wordpress site. (Centos 6.6 x86 ,LAMP) Since the size of the site is growing. (300GB+). Now I divide it into 3 server.
domain: www.example.com
server1 46.192.22.01 /var/www/public_html
/music
/video
server2 46.192.22.02 /var/www/public_html
/article
/photo
server3 172.192.22.03 /var/www/public_html
/products
/showroom
3 ips have already set in domain DNS. I want make them a cluster. custom access my site by diffrent URL, apache will choose the right server which land the corrent page files.
www.example.com/music/xxx mapping to server with 172.192.22.01
www.example.com/article/xxx mapping to server with 172.192.22.02
www.example.com/products/xxx mapping to server with 172.192.22.03
Now I used apache proxypassreverse.
/etc/httpd/conf/httpd.conf
In server1
ServerName www.example.com:80
<VirtualHost *:80>
ServerName www.example.com
ServerAlias www.example.com
DocumentRoot /var/www/html
<directory "/var/www/html">
Options Indexes FollowSymLinks
AllowOverride all
Order Deny,Allow
Deny from all
Allow from all
</directory>
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyRequests Off
ProxyPass /article http://46.192.22.02/article
ProxyPassReverse /article http://46.192.22.02/article
ProxyPass /photo http://46.192.22.02/photo
ProxyPassReverse /photo http://46.192.22.02/photo
ProxyPass /products http://46.192.22.03/products
ProxyPassReverse /products http://46.192.22.03/products
ProxyPass /showroom http://46.192.22.03/showroom
ProxyPassReverse /showroom http://46.192.22.03/showroom
</VirtualHost>
/etc/httpd/conf/httpd.conf
In server2
ServerName www.example.com:80
<VirtualHost *:80>
ServerName www.example.com
ServerAlias www.example.com
DocumentRoot /var/www/html
<directory "/var/www/html">
Options Indexes FollowSymLinks
AllowOverride all
Order Deny,Allow
Deny from all
Allow from all
</directory>
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyRequests Off
ProxyPass /music http://46.192.22.01/music
ProxyPassReverse /music http://46.192.22.01/music
ProxyPass /video http://46.192.22.01/video
ProxyPassReverse /video http://46.192.22.01/video
ProxyPass /products http://46.192.22.03/products
ProxyPassReverse /products http://46.192.22.03/products
ProxyPass /showroom http://46.192.22.03/showroom
ProxyPassReverse /showroom http://46.192.22.03/showroom
</VirtualHost>
/etc/httpd/conf/httpd.conf
In server3
ServerName www.example.com:80
<VirtualHost *:80>
ServerName www.example.com
ServerAlias www.example.com
DocumentRoot /var/www/html
<directory "/var/www/html">
Options Indexes FollowSymLinks
AllowOverride all
Order Deny,Allow
Deny from all
Allow from all
</directory>
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyRequests Off
ProxyPass /music http://46.192.22.01/music
ProxyPassReverse /music http://46.192.22.01/music
ProxyPass /video http://46.192.22.01/video
ProxyPassReverse /video http://46.192.22.01/video
ProxyPass /article http://46.192.22.02/article
ProxyPassReverse /article http://46.192.22.02/article
ProxyPass /photo http://46.192.22.02/photo
ProxyPassReverse /photo http://46.192.22.02/photo
</VirtualHost>
Now I can open my site with every folder www.example.com/music/xxx www.example.com/music/article, www.example.com/music/products,
But echo $_SERVER["SERVER_NAME"]
and echo $_SERVER['HTTP_HOST']
all return ip address. ServerName in httpd.conf seems not working. Where am I setting wrong?
Solution 1:
It seems that a proxy balancer snippet
is missing. According to this documentation a balancer setup looks as follows:
ProxyPass /special-area http://special.example.com smax=5 max=10
ProxyPass / balancer://mycluster/ stickysession=JSESSIONID|jsessionid nofailover=On
<Proxy balancer://mycluster>
BalancerMember ajp://1.2.3.4:8009
BalancerMember ajp://1.2.3.5:8009 loadfactor=20
# Less powerful server, don't send as many requests there,
BalancerMember ajp://1.2.3.6:8009 loadfactor=5
</Proxy>