global
log /dev/log local0
log /dev/log local1 notice
chroot /var/lib/haproxy
maxconn 10000
maxsessrate 10000
stats socket /run/haproxy/admin.sock mode 660 level admin expose-fd listeners
stats timeout 30s
user haproxy
group haproxy
daemon
ca-base /etc/ssl/certs
crt-base /etc/ssl/private
ssl-default-bind-ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384
ssl-default-bind-ciphersuites TLS_AES_128_GCM_SHA256:TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256
ssl-default-bind-options ssl-min-ver TLSv1.2 no-tls-tickets
tune.ssl.default-dh-param 2048
defaults
log global
mode http
option httplog
option dontlognull
timeout connect 5000
timeout client 50000
timeout server 50000
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
listen stats
bind 0.0.0.0:1080
mode http
option httplog
log global
stats enable
stats refresh 30s
stats uri /admin?stats
stats realm Private lands
stats auth admin:jt-admin
stats hide-version
stats admin if TRUE
backend per-ip
stick-table type ip size 50k expire 120m store gpc0,http_req_rate(1s)
frontend http_80_in
bind *:80
mode http
option httpclose
option forwardfor
option forwardfor header X-Client-IP
option forwardfor header X-Real-IP
option http-server-close
acl favicon path_beg -i /favicon.ico
http-request deny if favicon
acl aws_img_host hdr(host) -i image.test.cn
use_backend aws-img if aws_img_host
acl app_letsencrypt path_beg /.well-known/acme-challenge/
use_backend letsencrypt_backend if app_letsencrypt
acl project_host hdr_end(host) -i api.test.com
use_backend work if project_host
default_backend work
frontend https
bind *:443 ssl crt /etc/haproxy/ssl/api.test.com.pem
mode http
http-request add-header X-Forwarded-Proto https
option httpclose
option forwardfor
option http-server-close
acl hdr_connection_upgrade hdr(Connection) -i upgrade
acl hdr_upgrade_websocket hdr(Upgrade) -i websocket
use_backend websockets if hdr_connection_upgrade hdr_upgrade_websocket
acl project_host_https hdr_end(host) -i api.test.com
use_backend work if project_host_https
default_backend work
backend work
balance roundrobin
cookie SERVERID
server work-01 127.0.0.1:80 cookie 3 check inter 2000 rise 3 fall 3 weight 2
server work-02 127.0.0.2:80 cookie 2 check inter 2000 rise 3 fall 3 weight 2
backend letsencrypt_backend
http-request set-header Host letsencrypt.requests
dispatch 127.0.0.1:8000
backend aws-img
balance roundrobin
cookie SERVERID
http-request set-header Host s3.cn-north-1.amazonaws.com.cn
http-request replace-path (.*) /image\1
server aws s3.cn-north-1.amazonaws.com.cn
sudo haproxy -c -f haproxy.cfg
sudo service haproxy reload