load-balancing - 如何使用 HA 代理服务器作为负载均衡器
问题描述
我正在尝试使用 HA 代理服务器作为我的两个 Web 服务器之间的负载平衡器。各个服务器已启动并在指定端口上运行。但我无法通过 HA 代理服务器访问 Web 服务器。我已经使用标准设置配置了 HA 代理,如下所示
/etc/haproxy/haproxy.cfg
global
log 127.0.0.1 local0
chroot /var/lib/haproxy
pidfile /var/run/haproxy.pid
maxconn 4000
user haproxy
group haproxy
daemon
# turn on stats unix socket
stats socket /var/lib/haproxy/stats
#---------------------------------------------------------------------
# common defaults that all the 'listen' and 'backend' sections will
# use if not designated in their block
#---------------------------------------------------------------------
defaults
mode http
log global
option httplog
option dontlognull
option http-server-close
option forwardfor except 127.0.0.0/8
option redispatch
retries 3
timeout http-request 10s
timeout queue 1m
timeout connect 10s
timeout client 1m
timeout server 1m
timeout http-keep-alive 10s
timeout check 10s
maxconn 3000
#---------------------------------------------------------------------
# main frontend which proxys to the backends
#---------------------------------------------------------------------
frontend main *:80
mode http
default_backend app
backend app
balance roundrobin
option forwardfor
http-request set-header X-Forwarded-Port %[dst_port]
http-request add-header X-Forwarded-Proto https if { ssl_fc }
option httpchk HEAD / HTTP/1.1\r\nHost:localhost
server app1 10.368.240.116:9091
server app2 10.368.240.317:9092
#server app3 127.0.0.1:5003 check
#server app4 127.0.0.1:5004 check
我可以从我的 HA 代理主机成功地卷曲上述服务器
curl -i "10.368.240.116:9091"
HTTP/1.1 200 OK
curl -i "10.368.240.317:9091"
HTTP/1.1 200 OK
我的 HA 代理服务器正在侦听 80 端口但是当我点击它时,它给出了 503 错误,如下所示
curl -iv "127.0.0.1"
* About to connect() to 127.0.0.1 port 80 (#0)
* Trying 127.0.0.1...
* Connected to 127.0.0.1 (127.0.0.1) port 80 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.29.0
> Host: 127.0.0.1
> Accept: */*
>
* HTTP 1.0, assume close after body
< HTTP/1.0 503 Service Unavailable
HTTP/1.0 503 Service Unavailable
< Cache-Control: no-cache
Cache-Control: no-cache
< Connection: close
Connection: close
< Content-Type: text/html
Content-Type: text/html
<
<html><body><h1>503 Service Unavailable</h1>
No server is available to handle this request.
</body></html>
* Closing connection 0
谁能指导我在哪里做错了
解决方案
推荐阅读
- visual-studio-code - VS Code 中的“在文件中搜索”
- javascript - 如何使最小高度为 300 像素的 ng-bootstrap 轮播响应?
- scala - scala spark数据框爆炸很慢-因此,替代方法-从列中的数组创建列和行
- c - 如何调试 Lua 扩展随机段错误
- objective-c - Objective-C:最小的 init 与调用 initWith 的 init?
- r - 如何根据另一个向量的值范围获取向量的值范围?
- python - 出现运行时错误,但实际操作成功执行
- python - Python 3.6:加快 Pandas 数据框中的正则表达式替换
- python - 为什么我在 for 循环中收到无效的语法错误?
- python - 从熊猫中的相同列值中提取值数组