GO AWAY !

Request flow

Client --HTTPS--> HAProxy bastion (frontend https-in, *:443, TLS terminated, mode tcp, routing on SNI)
                   |
                   +-- a01.pepiniere.cloudns.ch --> backend a01 --HTTP + PROXY protocol------> A01 nginx :80  --> Flask :5000
                   |
                   +-- a02.pepiniere.cloudns.ch --> backend a02 --TLS + PROXY protocol-------> A02 nginx :443 --> Flask :5000

PROXY protocol: both sides or nothing

HAProxynginx listenResult
send-proxyproxy_protocolOK, real client IP
send-proxy-400 (A01:80) / TLS failure (A02:443)
-proxy_protocol"broken header", connection closed
--Works, but client IP = bastion

Summary

A01 (no SSL)A02 (bastion compatible)
Backend IP:port192.168.1.140:80192.168.1.143:443
HAProxy -> nginx encryptionNone (plain HTTP)TLS (self-signed, verify none)
PROXY protocolYes (send-proxy / proxy_protocol)Yes (send-proxy / proxy_protocol)
nginx SSLNoYes (self-signed certificate)
Client IP seen by the appReal client IPReal client IP

A01

HAProxy backend (bastion.j2)

backend a01
	balance roundrobin
	server a01_0 192.168.1.140:80 check send-proxy
	mode tcp

nginx (/etc/nginx/conf.d/client_ip.conf)

server {
    listen 80 proxy_protocol default_server;
    server_name _;

    # Real client IP taken from the PROXY protocol header sent by HAProxy (send-proxy)
    set_real_ip_from 10.0.0.0/8;
    set_real_ip_from 172.16.0.0/12;
    set_real_ip_from 192.168.0.0/16;
    real_ip_header    proxy_protocol;
    real_ip_recursive on;

    location / {
        proxy_pass http://127.0.0.1:5000;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}

No SSL between HAProxy and nginx (plain HTTP), but HAProxy prepends the PROXY protocol header, so nginx restores the real client IP before forwarding to the Flask application.

A02

HAProxy backend (bastion.j2)

backend a02
	balance roundrobin
	server a02_0 192.168.1.143:443 check send-proxy ssl verify none
	mode tcp

nginx (/etc/nginx/conf.d/client_ip.conf)

server {
    listen 80 default_server;
    listen 443 ssl proxy_protocol default_server;
    ssl_certificate     /etc/nginx/ssl/client_ip.crt;
    ssl_certificate_key /etc/nginx/ssl/client_ip.key;
    ssl_protocols       TLSv1.2 TLSv1.3;
    server_name _;

    # Real client IP taken from the PROXY protocol header sent by HAProxy (send-proxy)
    set_real_ip_from 10.0.0.0/8;
    set_real_ip_from 172.16.0.0/12;
    set_real_ip_from 192.168.0.0/16;
    real_ip_header    proxy_protocol;
    real_ip_recursive on;

    location / {
        proxy_pass http://127.0.0.1:5000;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}

HAProxy re-encrypts to nginx (self-signed certificate, not verified) and prepends the PROXY protocol header, so nginx restores the real client IP before forwarding to the Flask application.