HaProxy 配置错误

HaProxy 配置错误

我在端口 9000 和 9001 上运行了 2 个 springboot 应用程序。我还使用 docker 容器运行了 HaProxy。我的配置文件如下:

global

defaults
    mode http
    timeout connect 5000ms
    timeout client 5000ms
    timeout server 5000ms

frontend http-in
    bind *:80

    acl has_web1 path_beg /web1
    acl has_web2 path_beg /web2

    use_backend web1 if has_web1 
    use_backend web2 if has_web2 

    default_backend web1

backend web1
    server web1 127.0.0.1:9000 check 

backend web2
    server web2 127.0.0.1:9001 check 

当我尝试访问一个 URL,比如 localhost/web1 时,它给出错误代码 503。

有人能告诉我为什么会这样吗?docker compose 文件是:

version: '3'
services:
  #web1:
  #  image: dockercloud/hello-world
  #  container_name: web1
  #  ports:
  #    - "81:80"

  #web2:
  #  image: dockercloud/hello-world
  #  container_name: web2
  #  ports:
  #    - "82:80"    

  haproxy:
    build: ./haproxy
    container_name: haproxy
    ports:
      - "80:80"

Dockerfile 如下:

FROM haproxy:1.7

COPY haproxy.cfg /usr/local/etc/haproxy/haproxy.cfg

如果这很重要的话,我正在使用 Windows 工作。

编辑:我切换到 2.1.2 版本的 HaProxy 并收到以下警告

gs:

haproxy    | [NOTICE] 020/002817 (1) : New worker #1 (6) forked
haproxy    | [WARNING] 020/002817 (6) : Server web1/web1 is DOWN, reason: Layer4 connection problem, info: "Connection refused", check duration: 0ms. 0 active and 0 backup servers left. 0 sessions active, 0 requeued, 0 remaining in queue.
haproxy    | [ALERT] 020/002817 (6) : backend 'web1' has no server available!
haproxy    | [WARNING] 020/002818 (6) : Server web2/web2 is DOWN, reason: Layer4 connection problem, info: "Connection refused", check duration: 0ms. 0 active and 0 backup servers left. 0 sessions active, 0 requeued, 0 remaining in queue.
haproxy    | [ALERT] 020/002818 (6) : backend 'web2' has no server available!

这是因为 docker 容器吗?

相关内容