HAProxy拓展连接
此例简单介绍基于Docker的HAProxy反代
反代:
1.获取haproxy镜像
docker pull haproxy
2.写配置文件haproxy.cfg
1 global
2 #debug
3 chroot /var/lib/haproxy
4 user haproxy
5 group haproxy
6 pidfile /var/run/haproxy.pid
7
8 # Default SSL material locations
9 ca-base /etc/ssl/certs
10 crt-base /etc/ssl/private
11
12 # Default ciphers to use on SSL-enabled listening sockets.
13 ssl-default-bind-ciphers kEECDH+aRSA+AES:kRSA+AES:+AES256:RC4-SHA:!kEDH:!LOW:!EXP:!MD5:!aNULL:!eNULL
14
15 spread-checks 4
16 tune.maxrewrite 1024
17
18 defaults
19 mode http
20 balance roundrobin
21
22 option dontlognull
23 option dontlog-normal
24 option forwardfor
25 option redispatch
26
27 maxconn 5000
28 timeout connect 5s
29 timeout client 20s
30 timeout server 20s
31 timeout queue 30s
32 timeout http-request 5s
33 timeout http-keep-alive 15s
34
35 #errorfile 400 /etc/haproxy/errors/400.http
36 #errorfile 403 /etc/haproxy/errors/403.http
37 #errorfile 408 /etc/haproxy/errors/408.http
38 #errorfile 500 /etc/haproxy/errors/500.http
39 #errorfile 502 /etc/haproxy/errors/502.http
40 #errorfile 503 /etc/haproxy/errors/503.http
41 #errorfile 504 /etc/haproxy/errors/504.http
42
43 stats enable
44 stats refresh 30s
45 #stats hide-version
46 stats realm Strictly\ Private
47 stats auth admin:admin
48 stats uri /admin?stats
49
50 frontend http-out
51 option accept-invalid-http-request
52 bind *:8080
53 stats enable
54
55 default_backend sms
56
57 frontend http-in
58 option accept-invalid-http-request
59 bind *:80
60 stats enable
61 acl url_httpclient path_beg -i /sso/client/mail/
62 acl url_css path_beg -i /static/image/
63 use_backend nodes if url_httpclient
64 use_backend nodes if url_css
65
66 backend sms
67 option forwardfor header X-Real-IP
68 option http-server-close
69 server *.*.*.* *.*.*.*:8180 check
70
71 backend nodes
72 option forwardfor header X-Real-IP
73 option http-server-close
74 server *.*.*.* *.*.*.*:8180 check
3.启动容器
docker run --name haproxy -e LANG=en_US.UTF- -v /showcase/haproxy/haproxy.cfg:/etc/haproxy/haproxy.cfg --restart=always --net host -d haproxy:latest1