HAProxy此例簡單介紹基於docker的HAProxy反代
阿新 • • 發佈:2019-02-08
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