2022-10-01 20:06:19 +02:00
|
|
|
## {{ salt['pillar.get']('salt_managed', default='Salt Managed') }}
|
|
|
|
{%- from "haproxy/map.jinja" import haproxy,certs with context %}
|
|
|
|
|
2022-10-23 16:37:53 +02:00
|
|
|
{%- macro internal() -%}
|
|
|
|
acl internal src -f {{ haproxy.config.dir }}/maps/access
|
2022-10-01 20:06:19 +02:00
|
|
|
http-response return status 403 default-errorfiles if ! internal
|
|
|
|
{%- endmacro -%}
|
|
|
|
|
2022-10-23 16:37:53 +02:00
|
|
|
{%- macro head() -%}
|
2022-10-01 20:06:19 +02:00
|
|
|
http-request return status 200 if { method -i HEAD }
|
|
|
|
{%- endmacro -%}
|
|
|
|
|
2022-10-23 16:37:53 +02:00
|
|
|
{%- macro serverheader() -%}
|
|
|
|
http-response set-header server "{{ haproxy.config.servername }}"
|
|
|
|
{%- endmacro -%}
|
|
|
|
|
|
|
|
{%- macro endpoints(servers, check, ssl) -%}
|
|
|
|
{%- for server in servers %}
|
|
|
|
server {{ server.name }} {{ server.name }}:{{ server.port }}{{ " check observe layer7 inter 1s fall 5 rise 5 " if check|default(true) }}{{ " ssl verify none " if ssl|default(false) }}
|
2022-10-01 20:06:19 +02:00
|
|
|
{%- endfor %}
|
|
|
|
{%- endmacro -%}
|
|
|
|
|
2022-10-23 16:37:53 +02:00
|
|
|
{%- macro cache() -%}
|
|
|
|
http-request cache-use static if { path_end .css .js .png .jpg }
|
|
|
|
http-response cache-store static
|
|
|
|
{%- endmacro -%}
|
|
|
|
|
|
|
|
{%- macro compression() -%}
|
|
|
|
compression algo gzip
|
|
|
|
compression type text/html text/plain text/css text/javascript application/javascript
|
|
|
|
{%- endmacro -%}
|
|
|
|
|
2022-10-01 20:06:19 +02:00
|
|
|
{%- macro admin() -%}
|
|
|
|
listen stats
|
|
|
|
mode http
|
|
|
|
bind *:7000 v4v6
|
|
|
|
stats enable
|
|
|
|
stats refresh 5s
|
|
|
|
stats uri /
|
|
|
|
{%- endmacro -%}
|
|
|
|
|
|
|
|
{%- macro api() -%}
|
2022-10-23 16:37:53 +02:00
|
|
|
stats socket ipv4@127.0.0.1:9990 level admin
|
|
|
|
stats socket /var/run/hap-lb.sock mode 666 level admin
|
|
|
|
stats timeout 2m
|
2022-10-01 20:06:19 +02:00
|
|
|
{%- endmacro %}
|
|
|
|
|
|
|
|
global
|
2022-10-23 16:37:53 +02:00
|
|
|
lua-prepend-path {{ haproxy.config.dir }}/scripts/?.lua
|
|
|
|
{%- for file in haproxy.scripts %}
|
|
|
|
{%- if not file.lib %}
|
|
|
|
lua-load {{ haproxy.config.dir }}/{{ file.name }}
|
|
|
|
{%- endif %}
|
2022-10-10 10:16:32 +02:00
|
|
|
{%- endfor %}
|
2022-10-01 20:06:19 +02:00
|
|
|
maxconn 1000
|
2022-10-23 16:37:53 +02:00
|
|
|
{%- if haproxy.config.api.enable %}
|
|
|
|
{{ api() }}
|
|
|
|
{%- endif %}
|
2022-10-01 20:06:19 +02:00
|
|
|
ssl-default-bind-ciphers {{ haproxy.config.ssl_ciphers|join(":") }}
|
|
|
|
ssl-default-bind-options {{ haproxy.config.ssl_options|join(" ") }}
|
|
|
|
ssl-default-server-ciphers {{ haproxy.config.ssl_ciphers|join(":") }}
|
|
|
|
ssl-default-server-options {{ haproxy.config.ssl_options|join(" ") }}
|
2022-10-23 16:37:53 +02:00
|
|
|
crt-base {{ haproxy.config.acme_fullchains_dir }}
|
|
|
|
ssl-dh-param-file {{ haproxy.config.acme_dh_dir }}/dh.pem
|
2022-10-01 20:06:19 +02:00
|
|
|
|
|
|
|
defaults
|
2022-10-23 16:37:53 +02:00
|
|
|
{%- for key, value in haproxy.config.defaults.items() %}
|
|
|
|
{{ key }} {{ value }}
|
2022-10-01 20:06:19 +02:00
|
|
|
{%- endfor %}
|
|
|
|
|
|
|
|
{%- if haproxy.config.admin %}
|
2022-10-10 10:16:32 +02:00
|
|
|
{{ admin() }}
|
2022-10-01 20:06:19 +02:00
|
|
|
{%- endif %}
|
|
|
|
|
2022-10-10 10:16:32 +02:00
|
|
|
cache static
|
2022-10-23 16:37:53 +02:00
|
|
|
total-max-size 256
|
2022-10-10 10:16:32 +02:00
|
|
|
max-object-size 50000
|
|
|
|
max-age 120
|
|
|
|
|
2022-10-23 16:37:53 +02:00
|
|
|
backend per_ip_rates
|
|
|
|
stick-table type string size 1m expire 10s store http_req_rate(10s)
|
|
|
|
|
2022-10-01 20:06:19 +02:00
|
|
|
frontend http
|
|
|
|
bind *:80,:::80 v4v6
|
|
|
|
mode http
|
|
|
|
acl http ssl_fc,not
|
|
|
|
http-request redirect scheme https if http
|
|
|
|
|
|
|
|
frontend https
|
2022-10-23 16:37:53 +02:00
|
|
|
bind *:443,:::443 v4v6 ssl crt {{ haproxy.config.acme_fullchains_dir }}{% if haproxy.config.http2 %} alpn h2,http/1.1{% endif %}
|
|
|
|
mode http
|
|
|
|
option httplog
|
2022-10-01 20:06:19 +02:00
|
|
|
{%- for name, values in haproxy.config.vhosts.items() %}
|
|
|
|
use_backend {{ name }} if { hdr(Host) -i {{ values.host }} }
|
|
|
|
{%- endfor %}
|
2022-10-23 16:37:53 +02:00
|
|
|
http-request track-sc0 src table per_ip_rates
|
|
|
|
http-request capture req.hdr(User-Agent) len 200
|
|
|
|
http-request capture req.hdr(Content-Type) len 200
|
|
|
|
http-request capture req.hdr(Referer) len 200
|
|
|
|
http-request capture sc_http_req_rate(0) len 4
|
|
|
|
http-request deny deny_status 429 if { sc_http_req_rate(0) gt 100 }
|
|
|
|
http-request set-header x-proxy-id "{{ salt["grains.get"]("host") }}"
|
|
|
|
log-format "%ci:%cp [%tr] %ft %b/%s %TR/%Tw/%Tc/%Tr/%Ta %ST %B %CC %CS %tsc %ac/%fc/%bc/%sc/%rc %sq/%bq %hr %hs %{+Q}r"
|
2022-10-01 20:06:19 +02:00
|
|
|
default_backend nginx
|
|
|
|
|
|
|
|
{% for name, values in haproxy.config.vhosts.items() %}
|
|
|
|
backend {{ name }}
|
|
|
|
balance {{ values.balance|default("roundrobin") }}
|
2022-10-23 16:37:53 +02:00
|
|
|
mode http
|
|
|
|
option forwardfor
|
|
|
|
{%- if values.head|default(false) %}
|
|
|
|
{{ head() }}
|
2022-10-01 20:06:19 +02:00
|
|
|
{%- endif %}
|
2022-10-23 16:37:53 +02:00
|
|
|
|
|
|
|
{%- if values.compression|default(true) %}
|
|
|
|
{{ compression() }}
|
|
|
|
{%- endif %}
|
|
|
|
|
2022-10-10 10:16:32 +02:00
|
|
|
{%- if values.usecache|default(true) %}
|
2022-10-23 16:37:53 +02:00
|
|
|
{{ cache() }}
|
|
|
|
{%- endif %}
|
|
|
|
|
|
|
|
{%- if values.serverheader|default(true) %}
|
|
|
|
{{ serverheader() }}
|
2022-10-10 10:16:32 +02:00
|
|
|
{%- endif %}
|
2022-10-23 16:37:53 +02:00
|
|
|
|
|
|
|
{%- if values.internal|default(false) %}
|
|
|
|
{{ internal() }}
|
2022-10-01 20:06:19 +02:00
|
|
|
{%- endif %}
|
2022-10-23 16:37:53 +02:00
|
|
|
{{- endpoints(values.servers, values.check, values.ssl) }}
|
|
|
|
{% endfor -%}
|
2022-10-01 20:06:19 +02:00
|
|
|
|
|
|
|
{% for name, values in haproxy.config.services.items() %}
|
|
|
|
listen {{ name }}
|
|
|
|
bind :::{{ values.port }} v4v6
|
|
|
|
mode tcp
|
2022-10-23 16:37:53 +02:00
|
|
|
option tcplog
|
2022-10-01 20:06:19 +02:00
|
|
|
{%- if values.type == "postgres" %}
|
|
|
|
option pgsql-check user postgres
|
|
|
|
{%- endif %}
|
|
|
|
default-server inter 3s fall 3
|
2022-10-23 16:37:53 +02:00
|
|
|
{%- for server in values.servers %}
|
|
|
|
server {{ server.name }} {{ server.name }}:{{ server.port }} check {{ "backup" if server.backup|default(false) }} port {{ server.port }}
|
2022-10-01 20:06:19 +02:00
|
|
|
{%- endfor %}
|
2022-10-23 16:37:53 +02:00
|
|
|
{% endfor -%}
|