我使用PLAY Framework 2.2.1制作了一个应用程序(名称:osc_poc),并将源文件夹复制到另一个目标位置创建应用程序的第二个实例。
我使用两个具有不同端口的终端启动应用程序:
play -> to launch the play console in each terminal
run 9850 -> to deploy the first app with port 9850 in terminal 1
run 9851 -> to deploy the second app with port 9851 in terminal 2
然后我安装了Apache HTTPD服务器2.2.25,配置如下:
在 httpd.conf 中:
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
LoadModule proxy_http_module modules/mod_proxy_http.so
在 httpd-vhosts.conf 中:
<VirtualHost osf_poc.com:80>
ServerName osf_poc.com
<Location /balancer-manager>
SetHandler balancer-manager
Order Deny,Allow
Deny from all
Allow from .osf_poc.com
</Location>
<Proxy balancer://mycluster>
BalancerMember http://localhost:9850
BalancerMember http://localhost:9851 status=+H
</Proxy>
<Proxy *>
Order Allow,Deny
Allow From All
</Proxy>
ProxyPreserveHost On
ProxyPass /balancer-manager !
ProxyPass / balancer://mycluster/
ProxyPassReverse / http://localhost:9850/
ProxyPassReverse / http://localhost:9851/
</VirtualHost
而且我不知道要启动什么来访问负载均衡器 IP...
如果我去:
http://localhost:9850/
我可以看到第一个应用程序
如果我去:
http://localhost/
我可以看到来自 Apache 的消息 It Works...
请你帮我找到解决方案吗?谢谢
最佳答案
已解决,配置如下:
在 httpd.conf 中:
Include conf/extra/httpd-vhosts.conf
在 httpd-vhosts.conf 中(作为第一个 VirtualHost block ):
<VirtualHost *:80>
ServerName osf_poc.com
<Location /balancer-manager>
SetHandler balancer-manager
Order Deny,Allow
Deny from all
Allow from .osf_poc.com
</Location>
<Proxy balancer://mycluster>
BalancerMember http://localhost:9850
BalancerMember http://localhost:9851 status=+H
</Proxy>
<Proxy *>
Order Allow,Deny
Allow From All
</Proxy>
ProxyPreserveHost On
ProxyPass /balancer-manager !
ProxyPass / balancer://mycluster/
ProxyPassReverse / http://localhost:9850/
ProxyPassReverse / http://localhost:9851/
</VirtualHost
只需启动http://localhost/
即可平衡!
不知道下面的代码是否必要:
ServerName osf_poc.com
<Location /balancer-manager>
SetHandler balancer-manager
Order Deny,Allow
Deny from all
Allow from .osf_poc.com
</Location>
谢谢大家
关于apache - 设置 2 个 Play 框架实例的负载均衡器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21022934/