version: '3.8'
services:
  haproxy:
    image: haproxy:latest
    ports:
      - "80:80"
      - "443:443"
      - "8888:8888"
    volumes:
      - ./haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg
    restart: always
    entrypoint:
      - sh
      - -euc
      - |
        /bin/cat <<'EOF'>/usr/local/etc/haproxy/haproxy.cfg
        global
          maxconn 2000
          tune.ssl.default-dh-param 2048

        defaults
          mode http
          timeout connect 5s
          timeout client 50s
          timeout server 50s

        frontend http_frontend
          bind *:80
          default_backend http_backend

        backend http_backend
          balance roundrobin
          server web1 192.168.0.101:80 check
          server web2 192.168.0.102:80 check

        frontend tcp_frontend
          bind *:8888
          default_backend tcp_backend

        backend tcp_backend
          balance roundrobin
          server app1 192.168.0.201:8888 check
          server app2 192.168.0.202:8888 check

        frontend udp_frontend
          bind *:53 udp
          default_backend udp_backend

        backend udp_backend
          balance roundrobin
          server dns1 192.168.0.251:53 check
          server dns2 192.168.0.252:53 check

        frontend https_frontend
          bind *:443 ssl crt /etc/ssl/certs/mycert.pem
          default_backend https_backend

        backend https_backend
          balance roundrobin
          server secure1 192.168.0.301:443 check
          server secure2 192.168.0.302:443 check
        EOF
        haproxy -f /usr/local/etc/haproxy/haproxy.cfg
    networks:
      haproxy-network:
        ipv4_address: 172.18.19.31

networks:
  haproxy-network:
    driver: bridge
    ipam:
      config:
        - subnet: 172.18.19.0/24
    name: haproxy-network
最后修改:2023 年 11 月 02 日
如果觉得我的文章对你有用,请随意赞赏