HAProxy拓展连接
此例简单介绍基于docker的HAProxy反代
反代:
1.获取haproxy镜像

docker pull haproxy

2.写配置文件haproxy.cfg

global
    #debug
    chroot /var/lib/haproxy
    user haproxy
    group haproxy
    pidfile /var/run/haproxy.pid

    # Default SSL material locations
    ca-base /etc/ssl/certs
    crt-base /etc/ssl/private

    # Default ciphers to use on SSL-enabled listening sockets.
    ssl-default-bind-ciphers kEECDH+aRSA+AES:kRSA+AES:+AES256:RC4-SHA:!kEDH:!LOW:!EXP:!MD5:!aNULL:!eNULL

    spread-checks 4
    tune.maxrewrite 1024

defaults
    mode    http
    balance roundrobin

    option  dontlognull
    option  dontlog-normal
    option  forwardfor
    option  redispatch

    maxconn 5000
    timeout connect 5s
    timeout client  20s
    timeout server  20s
    timeout queue   30s
    timeout http-request 5s
    timeout http-keep-alive 15s

    #errorfile 400 /etc/haproxy/errors/400.http
    #errorfile 403 /etc/haproxy/errors/403.http
    #errorfile 408 /etc/haproxy/errors/408.http
    #errorfile 500 /etc/haproxy/errors/500.http
    #errorfile 502 /etc/haproxy/errors/502.http
    #errorfile 503 /etc/haproxy/errors/503.http
    #errorfile 504 /etc/haproxy/errors/504.http

    stats enable
    stats refresh 30s
    #stats hide-version
    stats realm Strictly\ Private
    stats auth admin:admin
    stats uri /admin?stats

frontend http-out
    option accept-invalid-http-request
    bind *:8080
    stats enable

    default_backend sms

frontend http-in
    option accept-invalid-http-request
    bind *:80
    stats enable
    acl url_httpclient path_beg   -i /sso/client/mail/
    acl url_css path_beg   -i /static/image/
    use_backend nodes if url_httpclient
    use_backend nodes if url_css

backend sms
    option forwardfor header X-Real-IP
    option http-server-close
    server *.*.*.* *.*.*.*:8180 check

backend nodes
    option forwardfor header X-Real-IP
    option http-server-close
    server *.*.*.* *.*.*.*:8180 check

3.启动容器

docker run --name haproxy -e LANG=en_US.UTF-8 -v /showcase/haproxy/haproxy.cfg:/etc/haproxy/haproxy.cfg --restart=always --net host -d haproxy:latest
Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐