Tech Tip: Fixing 421 Misdirected Request SNI Issues Between HAProxy and Apache

Created using Perplixity AI

Tech Tip: Fixing 421 Misdirected Request SNI Issues Between HAProxy and Apache

Overview

The HTTP 421 Misdirected Request error occurs when Apache receives an HTTPS request with an SNI hostname that doesn’t match its configured virtual hosts. This often happens when HAProxy is used as a reverse proxy in front of Apache and does not properly forward or handle the Server Name Indication (SNI) during TLS negotiation.


Why It Happens


How to Fix It

HAProxy Configuration (SSL Passthrough)

frontend https-in
    bind *:443 ssl crt /etc/ssl/certs/haproxy.pem
    mode tcp
    tcp-request inspect-delay 5s
    tcp-request content accept if { req_ssl_hello_type 1 }
    default_backend apache-https-backend

backend apache-https-backend
    mode tcp
    server apache1 192.168.0.2:443 send-proxy-v2 ssl verify none sni str(1,32)

Key points:

HAProxy Configuration (SSL Termination)

frontend https-in
    bind *:443 ssl crt /etc/ssl/certs/haproxy.pem
    mode http
    default_backend apache-backend

backend apache-backend
    mode http
    server apache1 192.168.0.2:80 check

Notes:


Apache Virtual Host Example

<VirtualHost *:443>
    ServerName example.com
    ServerAlias www.example.com
    SSLEngine on
    SSLCertificateFile /etc/ssl/certs/example.crt
    SSLCertificateKeyFile /etc/ssl/private/example.key
</VirtualHost>

Testing & Validation

Use curl to test and confirm no 421 errors:

curl -IkH "Host: example.com" https://haproxy-ip

Summary

This tip helps avoid 421 Misdirected Request errors in modern HAProxy-Apache reverse proxy TLS setups.