我用HTTPD设置了3个Docker容器,这些容器显示了非常简单的网页作为示例:
httpd.conf文件中的反向代理工作正常。
我现在正在尝试筛选一个负载平衡器,该负载平衡器允许用户转到/ griffin,它将把它们任意发送到#1或#2网络服务器(即httpd1或httpd2),从而显示使用Chris或Meg的图片。
负载均衡器的工作方式确实导致页面被加载,但是图像丢失。
# --------------------------------------------------------------------
# Simple reverse proxies
# --------------------------------------------------------------------
ProxyRequests Off
RewriteEngine On
RewriteRule ^/chris$ /chris/ [R]
<Location /chris>
ProxyPass http://httpd1:80/
ProxyPassReverse http://httpd1:80/
ProxyHTMLEnable On
ProxyHTMLURLMap http://httpd1:80/ /chris/
ProxyHTMLURLMap / /chris/
</Location>
RewriteRule ^/meg$ /meg/ [R]
<Location /meg>
ProxyPass http://httpd2:80/
ProxyPassReverse http://httpd2:80/
ProxyHTMLEnable On
ProxyHTMLURLMap http://httpd2:80/ /meg/
ProxyHTMLURLMap / /meg/
</Location>
# --------------------------------------------------------------------
# Load balancer
# --------------------------------------------------------------------
<Proxy balancer://mycluster>
BalancerMember http://localhost:8080/chris
BalancerMember http://localhost:8080/meg
ProxySet lbmethod=byrequests
</Proxy>
RewriteRule ^/griffin$ /griffin/ [R]
ProxyPass "/griffin/" "balancer://mycluster"
ProxyPassReverse "/griffin/" "balancer://mycluster"
<Location "/balancer-manager">
SetHandler balancer-manager
</Location>
对http://192.168.99.100:8080/griffin执行GET请求会产生:
192.168.99.1 - - [29/Sep/2018:11:28:52 +0000] "GET /griffin/ HTTP/1.1" 200 302 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36"
127.0.0.1 - - [29/Sep/2018:11:28:52 +0000] "GET /chris/ HTTP/1.1" 200 302 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36"
192.168.99.1 - - [29/Sep/2018:11:28:53 +0000] "GET /griffin/chris-griffin.jpg HTTP/1.1" 500 528 "http://192.168.99.100:8080/griffin/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36"
如果每个Web服务器(httpd1和httpd2)都包含图像,它仍然不起作用,这表明可能是URL重写问题。但是,这就是负载均衡器使用反向代理的原因。我还尝试过直接在负载平衡配置中引用httpd1和httpd2服务器,但无济于事。
如果我不了解任何帮助,将不胜感激。