haproxy 部屬
1 2
| apt update apt install haproxy -y
|
編輯config
1
| vi /etc/haproxy/haproxy.cfg
|
簡單部屬
1 2 3 4 5 6 7 8
| frontend http_front bind *:80 default_backend http_back
backend http_back balance roundrobin server server1 192.168.22.2:80 check server server2 192.168.22.3:80 check
|
將所有網址導向443
1 2 3
| frontend http-in bind *:80 redirect scheme https code 301 if !{ ssl_fc }
|
加入證書
1 2 3 4 5 6 7 8 9
| fontend https-in bind *:443 ssl crt /ssl/haproxy.pem acl host_example hdr(host) -i a.example.com use_backend backend_example if host_example
backend backend_example balance roundrobin server server1 192.168.22.2:80 check server server2 192.168.22.3:80 check
|
檢查配置文件
haproxy -f haproxy.cfg -c
service haproxy restart