【问题标题】:apache httpd mod_proxy load balancing with multiple virtual hosts url redirection具有多个虚拟主机 url 重定向的 apache httpd mod_proxy 负载平衡
【发布时间】:2022-02-24 07:04:15
【问题描述】:

场景:
操作系统 centos
网络服务器 apache http 版本 2.2.23
两个 weblogic 服务器集群
两个网络服务器

上面是硬件负载平衡器

基本上想做流量的url重定向和负载均衡(不修改会话)

当我输入 agent.abconline.com 时,它应该被重定向到应用服务器 192.168.0.1:7001/agent staging.abconline.com 应该被重定向到 192.168.0.1;7001/staging

上面说我可以单独使用 mod_rewrite,但是在尝试使用 mod_proxy 和负载平衡时,我无法重定向到所述 URL

以下是配置

NameVirtualHost *:80
<VirtualHost *:80>
        ServerName agent.abconline.com
        RewriteEngine On

        <Proxy balancer://agentcluster>
         BalancerMember http://192.168.0.1:7003 route=1 loadfactor=50 retry=60
         BalancerMember http://192.168.0.2:7003 route=1 loadfactor=50 retry=60
        </Proxy>

        # Redirect all non-static requests to agent
        RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
        RewriteRule ^/(.*)$ balancer://agentcluster%{REQUEST_URI} [P,QSA,L]

        ProxyPass /abc-oper balancer://agentcluster/abc-oper
        ProxyPassReverse /abc-oper balancer://agentcluster/abc-oper
        ProxyPreserveHost on

        SetEnv force-proxy-request-1.0 1
        SetEnv proxy-nokeepalive 1

        <Proxy *>
         Order deny,allow
         Allow from all
        </Proxy>

        ErrorLog /apps/apache/logs/agent.abconline.com.error.log
        CustomLog /apps/apache/logs/agent.abconline.com.access.log combined
        LogLevel debug
</VirtualHost>

<VirtualHost *:80>
        ServerName staging.abconline.com
        RewriteEngine On

        <Proxy balancer://stagingcluster>
         BalancerMember http://192.168.0.1:7003 route=1 loadfactor=50 retry=60
         BalancerMember http://192.168.0.2:7003 route=1 loadfactor=50 retry=60
        </Proxy>

        # Redirect all non-static requests to agent
        RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
        RewriteRule ^/(.*)$ balancer://stagingcluster%{REQUEST_URI} [P,QSA,L]

        ProxyPass /abc-oper balancer://stagingcluster/abc-oper
        ProxyPassReverse /abc-oper balancer://stagingcluster/abc-oper
        ProxyPreserveHost on

        SetEnv force-proxy-request-1.0 1
        SetEnv proxy-nokeepalive 1

        <Proxy *>
         Order deny,allow
         Allow from all
        </Proxy>

        ErrorLog /apps/apache/logs/staging.abconline.com.error.log
        CustomLog /apps/apache/logs/staging.abconline.com.access.log combined
        LogLevel debug
</VirtualHost>

【问题讨论】:

    标签: mod-rewrite weblogic load-balancing mod-proxy


    【解决方案1】:

    您没有将适当的 /agent/staging 上下文添加到反向代理规则中,并且显然在退出时删除了上下文,例如

    RewriteRule      / balancer://stagingcluster/staging%{REQUEST_URI} [P,QSA,L]
    ProxyPassReverse / balancer://stagingcluster/staging
    
    
    # Possibly also require a:
    #ProxyHTMLURLMap balancer://stagingcluster/staging   /
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-10-23
      • 2015-04-24
      • 2013-09-27
      • 2016-03-31
      • 2013-02-05
      • 2017-10-09
      • 2018-09-08
      • 2017-11-17
      相关资源
      最近更新 更多