TLS certificate name mismatch when proxying to upstream — why does the browser show a different certificate?
Environment
NGINX reverse proxy on Debian 12 terminating TLS for public host, proxying to an internal HTTPS upstream that uses a certificate issued for its own name. Browsers show a common-name mismatch when accessing the public hostname.
Symptoms
Browser warns of certificate name mismatch (certificate common name or SANs do not include the requested host). curl -v to the proxy shows the proxy's certificate, while direct connect to the upstream returns a different certificate.
Observations
Upstream servers host valid certificates for their hostnames (checked directly). The proxy configuration lacks explicit proxy_ssl_name or proxy_ssl_server_name may be off. Some clients succeed while others fail (different SNI handling).
Already attempted
Restarted NGINX after config edits; toggled proxy_ssl_server_name on and off but didn't validate using openssl s_client with and without -servername yet.
Diagnostic steps
- From the proxy host, test the upstream TLS handshake with SNI: openssl s_client -connect upstream:443 -servername expected.hostname and without SNI: openssl s_client -connect upstream:443
- What the result means: If the certificate returned differs between commands, the upstream selects certs based on SNI. A correct cert with -servername but a default or different cert without it indicates SNI must be sent by the proxy.
- Inspect NGINX proxy config for proxy_ssl_server_name on; check proxy_ssl_name if present and whether proxy_pass uses a hostname or IP
- What the result means: If proxy_pass uses an IP, NGINX cannot infer the name; enabling proxy_ssl_server_name and setting proxy_ssl_name to the desired hostname will instruct NGINX to send SNI. If proxy_ssl_server_name is off, NGINX won't send SNI and upstream may return a default cert.
- Use curl --resolve 'public-host:443:PROXY_IP' -vk https://public-host/ to test client→proxy TLS and openssl s_client to test proxy→upstream separately; review nginx error.log and access.log for proxy_ssl verification messages
- What the result means: If client→proxy TLS serves the proxy cert and proxy→upstream returns the wrong cert when checked separately, the issue is upstream name selection. If client sees proxy cert mismatch, adjust proxy TLS cert. Logs may show certificate verification failures if proxy validates upstream certs.
- If proxy validates upstream cert, ensure proxy trusts upstream CA: check proxy's trusted certificate store and proxy_ssl_trusted_certificate directive
- What the result means: If trust is missing, proxy may fail verification and either abort or accept defaults; configuring the correct trusted CA allows proxy to validate and also to use proxy_ssl_server_name safely.
Confirmed fixes
No fix has been independently verified for this scenario. Treat the causes below as diagnostic hypotheses.
Question
How to verify whether SNI or proxy_ssl_name is the cause and how to make the proxy present the correct server name to the upstream so the right certificate is served?
Verified community troubleshooting
Confirm whether the mismatch is happening on client→proxy TLS or proxy→upstream TLS. From the proxy host run: openssl s_client -connect upstream:443 -servername desired.hostname and repeat without -servername. If the cert changes, the upstream picks certs by SNI and your proxy must send the server name. For NGINX, ensure proxy_ssl_server_name on; if you proxy by IP, also set proxy_ssl_name to the hostname. After changes, test client access (curl -vk) and verify upstream cert with openssl s_client. Keep old nginx config and certs to rollback if needed and add upstream CA to proxy truststore if verification is required.
Incident analysis
Most likely causes
Summary
Suggested Fixes
Continue troubleshooting
Related troubles
Matched from the title, description and tags
- Web Development52% match
Why does the browser show a different TLS certificate when proxying through my Nginx reverse proxy?
Open1 answer - Networking29% match
CORS preflight (OPTIONS) passes on localhost but fails when routed through Nginx reverse proxy — why?
Open1 answer - Networking24% match
WebSocket closes after fixed idle period when routed through Nginx reverse proxy
Open1 answer - Networking21% match
Chunked Transfer-Encoding uploads fail with 413 only through TLS-terminating NGINX proxy
Open0 answers - Servers21% match
Nginx returns 502 Bad Gateway when proxying to local Node.js upstream intermittently
Open0 answers