简体   繁体   中英

Apache multiple ports binded

I have configured my httpd.conf in apache to point to multiple site based on the port numbers requested. This configuration works fine when deployed in windows, but when I move the same configuration to linux, it does not work, please assist.

Below is the snippet for the same.

Listen 81
Listen 82

<VirtualHost *:81>  
    RewriteEngine on
    RewriteCond %{HTTPS} on
    RewriteRule ^((?!/services).)*$ http://%{HTTP_HOST}%{REQUEST_URI}
    ServerAdmin root@localhost
    ProxyRequests off
    <Proxy *>
        Order deny,allow
        Allow from all
    </Proxy>
    ProxyPreserveHost On
    Header add Set-Cookie "ROUTEID=.%{BALANCER_WORKER_ROUTE}e; path=/" env=BALANCER_ROUTE_CHANGED  
    ProxyPass / balancer://mycluster/ stickysession=ROUTEID
    <Proxy balancer://mycluster>
        Order deny,allow
        Allow from all
        BalancerMember http://10.236.75.102:9765 route=AS1 loadfactor=100  timeout=600 Keepalive=On
    </Proxy>
    <Location /balancer-manager>
        SetHandler balancer-manager
        Order deny,allow
        Allow from all
<IfModule mod_headers.c>
       SetEnvIf Origin (.*) AccessControlAllowOrigin=$1
       Header add Access-Control-Allow-Origin %{AccessControlAllowOrigin}e env=AccessControlAllowOrigin
       Header set Access-Control-Allow-Credentials true
</IfModule>

    </Location>
</VirtualHost>

<VirtualHost *:82>  
    RewriteEngine on
    RewriteCond %{HTTPS} on
    RewriteRule ^((?!/services).)*$ http://%{HTTP_HOST}%{REQUEST_URI}
    ServerAdmin root@localhost
    ProxyRequests off
    <Proxy *>
        Order deny,allow
        Allow from all
    </Proxy>
    ProxyPreserveHost On
    Header add Set-Cookie "ROUTEID=.%{BALANCER_WORKER_ROUTE}e; path=/" env=BALANCER_ROUTE_CHANGED  
    ProxyPass / balancer://mycluster/ stickysession=ROUTEID
    <Proxy balancer://mycluster>
        Order deny,allow
        Allow from all
        BalancerMember http://10.236.75.101:9767/carbon/ route=UES1 loadfactor=100  timeout=600 Keepalive=On
    </Proxy>
    <Location /balancer-manager>
        SetHandler balancer-manager
        Order deny,allow
        Allow from all
<IfModule mod_headers.c>
       SetEnvIf Origin (.*) AccessControlAllowOrigin=$1
       Header add Access-Control-Allow-Origin %{AccessControlAllowOrigin}e env=AccessControlAllowOrigin
       Header set Access-Control-Allow-Credentials true
</IfModule>

I found the answer, and below is the final solution,

<VirtualHost *:81>
        RewriteEngine on
        RewriteCond %{HTTPS} on
        RewriteRule ^((?!/services).)*$ http://%{HTTP_HOST}%{REQUEST_URI}
        ServerAdmin root@localhost
        ProxyRequests off
        <Proxy *>
                Order deny,allow
                Allow from all
        </Proxy>
        ProxyPreserveHost On
        Header add Set-Cookie "ROUTEID=.%{BALANCER_WORKER_ROUTE}e; path=/" env=BALANCER_ROUTE_CHANGED
        ProxyPass / balancer://mycluster/ stickysession=ROUTEID
        <Proxy balancer://mycluster>
                Order deny,allow
                Allow from all
                BalancerMember http://10.236.75.102:9765 route=AS1 loadfactor=100  timeout=600 Keepalive=On
        </Proxy>
        <Location /balancer-manager>
                SetHandler balancer-manager
                Order deny,allow
                Allow from all
<IfModule mod_headers.c>
       SetEnvIf Origin (.*) AccessControlAllowOrigin=$1
       Header add Access-Control-Allow-Origin %{AccessControlAllowOrigin}e env=AccessControlAllowOrigin
       Header set Access-Control-Allow-Credentials true
</IfModule>
        </Location>
</VirtualHost>

<VirtualHost *:82>
        RewriteEngine on
        RewriteCond %{HTTPS} on
        RewriteRule ^((?!/services).)*$ http://%{HTTP_HOST}%{REQUEST_URI}
        ServerAdmin root@localhost
        ProxyRequests off
        <Proxy *>
                Order deny,allow
                Allow from all
        </Proxy>
ProxyPreserveHost On
        Header add Set-Cookie "ROUTEID=.%{BALANCER_WORKER_ROUTE}e; path=/" env=BALANCER_ROUTE_CHANGED
        ProxyPass / balancer://mycluster1/ stickysession=ROUTEID
        <Proxy balancer://mycluster1>
                Order deny,allow
                Allow from all
                BalancerMember http://10.236.75.101:9767/carbon route=UES1 loadfactor=100  timeout=600 Keepalive=On
        </Proxy>
        <Location /balancer-manager>
                SetHandler balancer-manager
                Order deny,allow
                Allow from all
<IfModule mod_headers.c>
       SetEnvIf Origin (.*) AccessControlAllowOrigin=$1
       Header add Access-Control-Allow-Origin %{AccessControlAllowOrigin}e env=AccessControlAllowOrigin
       Header set Access-Control-Allow-Credentials true
</IfModule>
        </Location>
</VirtualHost>

A similar configuration is also required in httpd-ssl.conf

There should be multiple entries for Virtualhost like :

<VirtualHost *:446>

.......

 ProxyPreserveHost On
        Header add Set-Cookie "ROUTEID=.%{BALANCER_WORKER_ROUTE}e; path=/" env=BALANCER_ROUTE_CHANGED
        ProxyPass / balancer://mycluster1/ stickysession=ROUTEID
        <Proxy balancer://mycluster1>
                Order deny,allow
                Allow from all
                BalancerMember http://10.236.75.101:9767/carbon route=UES1 loadfactor=100  timeout=600 Keepalive=On
        </Proxy>
        <Location /balancer-manager>
                SetHandler balancer-manager
                Order deny,allow
                allow from all
                SSLRequireSSL
        </Location>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM