1
0
Fork 0
home-stack-ansible/roles/haproxy/templates/haproxy.cfg

106 lines
2.7 KiB
INI
Raw Normal View History

2021-08-25 04:33:56 +00:00
global
daemon
maxconn 1024
log 127.0.0.1 local0
stats timeout 30s
2021-08-26 05:09:42 +00:00
tune.ssl.default-dh-param 2048
2021-08-25 04:33:56 +00:00
defaults
timeout connect 5s
2021-08-28 04:32:15 +00:00
timeout client 120s
timeout server 120s
2021-08-25 04:33:56 +00:00
log global
default-server init-addr last,none resolvers dns
resolvers dns
parse-resolv-conf
## FRONTENDS ##
# haproxy stuff
frontend http_management
bind *:8080
mode http
# redirects /status to haproxy monitor
monitor-uri /status
# redirects /stats to stats backend
acl prefixed-with-stats path_beg -i /stats
use_backend haproxy_stats if prefixed-with-stats
# redirects /metrics to metrics backend
acl prefixed-with-metrics path_beg -i /metrics
use_backend haproxy_metrics if prefixed-with-metrics
2021-08-26 05:09:42 +00:00
# http frontend
frontend https_in
2021-08-25 04:33:56 +00:00
bind *:80
2021-08-26 05:09:42 +00:00
# backend is assumed to be http, perform ssl termination here
bind *:443 ssl crt /etc/letsencrypt/live/{{ letsencrypt.domains[0] }}/{{ letsencrypt.domains[0] }}.pem alpn h2,http/1.1
2021-08-25 04:33:56 +00:00
2021-08-26 05:09:42 +00:00
mode http
option forwardfor
2021-08-25 04:33:56 +00:00
2021-08-26 05:09:42 +00:00
# force https
http-request redirect scheme https unless { ssl_fc }
2021-08-25 04:33:56 +00:00
2021-08-28 04:32:15 +00:00
# set HSTS
http-response set-header Strict-Transport-Security "max-age=15552000; includeSubDomains;"
2021-11-12 20:20:41 +00:00
# set X-Forwarded-Proto
http-request set-header X-Forwarded-Proto http if !{ ssl_fc }
http-request set-header X-Forwarded-Proto https if { ssl_fc }
2021-08-25 04:33:56 +00:00
# request is ssl
# tcp-request inspect-delay 5s
# tcp-request content accept if { req.ssl_hello_type 1 }
2021-08-26 05:09:42 +00:00
{% for http_route in https_routing %}
#use_backend https_{{ http_route.src[0]|replace('.','_') }} if { req.ssl_sni -i {% for src in http_route.src %}{{ src }} {% endfor %}}
use_backend https_{{ http_route.src[0]|replace('.','_') }} if { hdr_end(host) -i {% for src in http_route.src %}{{ src }} {% endfor %}}
2021-08-25 04:33:56 +00:00
{% endfor %}
## BACKENDS ##
2021-08-26 05:09:42 +00:00
# stat backend
2021-08-25 04:33:56 +00:00
backend haproxy_stats
mode http
stats uri /stats
stats enable
stats refresh 10s
stats auth admin:admin
2021-08-26 05:09:42 +00:00
# metric backend
2021-08-25 04:33:56 +00:00
backend haproxy_metrics
mode http
http-request use-service prometheus-exporter
2021-08-26 05:09:42 +00:00
{% for http_route in https_routing %}
2021-12-17 23:17:18 +00:00
# backend for {{ ', '.join(http_route.src) }}
2021-08-26 05:09:42 +00:00
backend https_{{ http_route.src[0]|replace('.','_') }}
mode http
2021-08-25 04:33:56 +00:00
balance roundrobin
2021-08-26 05:09:42 +00:00
{% for dst in http_route.dst %}
2021-12-17 23:17:18 +00:00
server {{ dst }} {{ dst }}{% if ':' not in dst %}:443{% endif %} check {% if http_route.ssl|default(true) %}ssl verify none alpn h2{% endif %}
2021-08-26 05:09:42 +00:00
{% endfor %}
2021-12-17 23:17:18 +00:00
2021-08-26 05:09:42 +00:00
{% endfor %}
## TCP ##
{% for tcp_route in tcp_routing %}
frontend tcp_{{ tcp_route.src }}
bind *:{{ tcp_route.src }}
mode tcp
use_backend tcp_{{ tcp_route.src }}
backend tcp_{{ tcp_route.src }}
mode tcp
{% for dst in tcp_route.dst %}
server {{ dst }} {{ dst }} check
2021-08-25 04:33:56 +00:00
{% endfor %}
{% endfor %}