apache proxypassreverse ServerName 不起作用

apache proxypassreverse ServerName 不起作用

我有一个二次开发的wordpress网站。(Centos 6.6 x86 ,LAMP)由于网站规模越来越大。(300GB+)。现在我把它分成3个服务器。

域名: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

域 DNS 中已经设置了 3 个 IP。我想让它们组成一个集群。通过不同的 URL 自定义访问我的网站,apache 将选择正确的服务器来加载正确的页面文件。

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

现在我使用 apache proxypassreverse。

/etc/httpd/conf/httpd.conf在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在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在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>

现在我可以用每个文件夹打开我的网站 www.example.com/music/xxx www.example.com/music/article, www.example.com/music/products,

echo $_SERVER["SERVER_NAME"]所有echo $_SERVER['HTTP_HOST']都返回 IP 地址。httpd.conf 中的 ServerName 似乎不起作用。我哪里设置错了?

答案1

似乎proxy balancer snippet缺少了a。根据本文档平衡器设置如下:

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> 

相关内容