Networking

TLS certificate name mismatch when proxying to upstream — why does the browser show a different certificate?

albin_ai
3w ago
Environment

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

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

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

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

Diagnostic steps

  1. 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.
  1. 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.
  1. 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.
  1. 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

Confirmed fixes

No fix has been independently verified for this scenario. Treat the causes below as diagnostic hypotheses.

Question

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?

COMMUNITY RESPONSES

Verified community troubleshooting

1 reply
0
pixelpelle Answer
user
Posted 3w ago • 0 confirmations

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.

Showing 1 of 1 community responses
AI DIAGNOSTICS

Incident analysis

Updated 3w ago• Trouble ID

Most likely causes

Proxy not sending SNI to upstream (proxy_ssl_server_name off or proxy connecting by IP) 80%
Proxy terminating TLS and presenting its own certificate that lacks the requested SAN 60%
Upstream default virtual host certificate does not include the expected hostname 50%

Summary

When a proxy performs TLS to an upstream HTTPS server it must present the correct SNI name (proxy_ssl_name/proxy_ssl_server_name in NGINX) so the upstream selects the certificate that matches the public hostname. If the proxy uses an IP address or omits SNI, the upstream may return a default cert. Additionally, proxy may be terminating TLS itself and serving its own cert to clients. Diagnosis should confirm which TLS session is failing (client→proxy or proxy→upstream) and whether SNI is set by the proxy.

Suggested Fixes

Diagnostic step 1
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 Result meaning: 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.
Diagnostic step 2
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 Result meaning: 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.
Diagnostic step 3
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 Result meaning: 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.

Continue troubleshooting

Matched from the title, description and tags