Apache多个端口绑定
Posted
技术标签:
【中文标题】Apache多个端口绑定【英文标题】:Apache multiple ports binded 【发布时间】:2016-01-17 09:16:13 【问题描述】:我在 apache 中配置了我的 httpd.conf,以根据请求的端口号指向多个站点。这个配置部署在windows下可以正常工作,但是当我把同样的配置移到linux上就不行了,求大神帮忙。
下面是相同的sn-p。
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_ROUTEe; 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 %AccessControlAllowOrigine 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_ROUTEe; 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 %AccessControlAllowOrigine env=AccessControlAllowOrigin
Header set Access-Control-Allow-Credentials true
</IfModule>
【问题讨论】:
【参考方案1】:我找到了答案,下面是最终的解决方案,
<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_ROUTEe; 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 %AccessControlAllowOrigine 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_ROUTEe; 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 %AccessControlAllowOrigine env=AccessControlAllowOrigin
Header set Access-Control-Allow-Credentials true
</IfModule>
</Location>
</VirtualHost>
httpd-ssl.conf中也需要类似的配置
Virtualhost 应该有多个条目,例如:
<VirtualHost *:446>
.......
ProxyPreserveHost On
Header add Set-Cookie "ROUTEID=.%BALANCER_WORKER_ROUTEe; 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>
【讨论】:
以上是关于Apache多个端口绑定的主要内容,如果未能解决你的问题,请参考以下文章