Files
infrastructure/roles/nginx/templates/nginx-hostname-vhost.conf.j2
Christian Heusel 9f9e4f4379 nginx: add stream deny front-proxy for fail2ban behind HAProxy
Behind the HAProxy ADN every packet arrives from an allowlisted ADN IP,
so an L3/L4 ban issued by fail2ban that targets the real client IP never
matches.

Add an opt-in L4 stream front-proxy (nginx_stream_deny) that terminates
the PROXY protocol, denies banned clients by their real IP before TLS is
terminated, then re-emits the PROXY protocol to loopback http listeners
so the real client IP is preserved.

Related-to: https://gitlab.archlinux.org/archlinux/infrastructure/-/work_items/766
Assisted-By: Claude Opus 4.8 <noreply@anthropic.com>
Signed-off-by: Christian Heusel <christian@heusel.eu>
2026-10-07 16:08:33 +02:00

29 lines
1.1 KiB
Django/Jinja

server {
{% if nginx_stream_deny %}
listen 127.0.0.1:8080 default_server proxy_protocol;
listen [::1]:8080 default_server proxy_protocol;
listen 127.0.0.1:8443 default_server ssl proxy_protocol;
listen [::1]:8443 default_server ssl proxy_protocol;
{% else %}
listen 80 default_server{{ ' proxy_protocol' if nginx_proxy_protocol_upstream_host or nginx_proxy_vendor }};
listen [::]:80 default_server{{ ' proxy_protocol' if nginx_proxy_protocol_upstream_host or nginx_proxy_vendor }};
listen 443 default_server ssl{{ ' proxy_protocol' if nginx_proxy_protocol_upstream_host or nginx_proxy_vendor }};
listen [::]:443 default_server ssl{{ ' proxy_protocol' if nginx_proxy_protocol_upstream_host or nginx_proxy_vendor }};
{% if nginx_enable_http3 %}
listen 443 default_server quic reuseport;
listen [::]:443 default_server quic reuseport;
{% endif %}
{% endif %}
http2 on;
ssl_reject_handshake on;
root /srv/http;
include snippets/letsencrypt.conf;
location / {
return 404;
}
}