Skip to content

Fix 421 Misdirected Request by adding proxy_ssl_server_name#688

Open
axcelx wants to merge 1 commit intoAnoopAlias:ndeploy4from
axcelx:patch-1
Open

Fix 421 Misdirected Request by adding proxy_ssl_server_name#688
axcelx wants to merge 1 commit intoAnoopAlias:ndeploy4from
axcelx:patch-1

Conversation

@axcelx
Copy link

@axcelx axcelx commented Jan 29, 2026

Problem
Sites intermittently return HTTP 421 "Misdirected Request" errors after failover/failback events. The error occurs on HTTPS requests and affects all clients.

Root Cause
When nginx proxies HTTPS requests to Apache on port 4430, it does not send the SNI (Server Name Indication) header. Apache has multiple SSL vhosts listening on port 4430 and relies on SNI to determine which vhost should handle the request. Without SNI, Apache cannot match the incoming request to the correct vhost and returns a 421 error.

The 421 response includes charset=iso-8859-1 indicating it originates from Apache, not nginx.

Solution
Add the following nginx directives to all SSL server blocks in conf/server.j2:

nginxproxy_ssl_server_name on;
proxy_ssl_name $host;

These directives instruct nginx to:

proxy_ssl_server_name on - Enable passing the SNI header when proxying to upstream SSL servers proxy_ssl_name $host - Use the requested hostname as the SNI value

Files Changed

conf/server.j2 - Added proxy SSL settings in all 5 SSL server blocks (after ssl_stapling on; directives)

Testing

Before fix: curl -Ik https://example.com returns HTTP 421
After fix: curl -Ik https://example.com returns HTTP 200

Problem
Sites intermittently return HTTP 421 "Misdirected Request" errors after failover/failback events. The error occurs on HTTPS requests and affects all clients.

Root Cause
When nginx proxies HTTPS requests to Apache on port 4430, it does not send the SNI (Server Name Indication) header. Apache has multiple SSL vhosts listening on port 4430 and relies on SNI to determine which vhost should handle the request. Without SNI, Apache cannot match the incoming request to the correct vhost and returns a 421 error.

The error message from nginx logs:
access forbidden by rule, client: x.x.x.x, server: _, request: "HEAD / HTTP/1.1", host: "example.com"

The 421 response includes charset=iso-8859-1 indicating it originates from Apache, not nginx.

Solution
Add the following nginx directives to all SSL server blocks in conf/server.j2:

nginxproxy_ssl_server_name on;
proxy_ssl_name $host;

These directives instruct nginx to:

proxy_ssl_server_name on - Enable passing the SNI header when proxying to upstream SSL servers
proxy_ssl_name $host - Use the requested hostname as the SNI value


Files Changed

conf/server.j2 - Added proxy SSL settings in all 5 SSL server blocks (after ssl_stapling on; directives)

Testing

Before fix: curl -Ik https://example.com returns HTTP 421
After fix: curl -Ik https://example.com returns HTTP 200
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Comments