Why does the browser show a different TLS certificate when proxying through my Nginx reverse proxy?
Environment
Nginx 1.18 running as TLS-terminating reverse proxy on Debian 11; upstream app on 10.0.0.20:8443 with its own cert; browser Chrome on macOS 13.4; SNI expected to be hostname.example.com.
Symptoms
Visiting https://hostname.example.com via proxy shows certificate valid for upstream.example.local (name mismatch). Directly connecting to upstream IP:8443 with host header absent returns a different certificate.
Observations
Browser error reports name mismatch (hostname vs cert SAN). Nginx access logs show request to upstream IP. Nginx config uses proxy_pass https://10.0.0.20:8443; no ssl_server_name directive currently set. Upstream serves a certificate with CN/SAN upstream.example.local.
Already attempted
Cleared browser cache and restarted Nginx. Tested connecting to upstream IP with curl but did not set SNI. Did not modify proxy SSL settings yet.
Diagnostic steps
- From a machine that follows the same path as the browser, run an SNI-aware TLS client (openssl s_client -connect proxy:443 -servername hostname.example.com) and record the certificate subject and SANs presented.
- What the result means: If the presented cert matches hostname.example.com, the proxy is correctly presenting that cert. If it matches upstream.example.local, the proxy is forwarding TLS or the client is reaching the upstream directly. If a default/fallback cert appears, SNI likely not delivered to the TLS server that answered.
- Run the same command but target the upstream socket (openssl s_client -connect 10.0.0.20:8443 -servername hostname.example.com) and compare the certificate returned when SNI is set versus omitted.
- What the result means: If adding -servername changes the cert to the expected hostname, the upstream supports SNI but returned the fallback when SNI was missing; proxy must forward SNI. If the upstream never returns hostname.example.com, the upstream lacks that certificate.
- Inspect Nginx config for ssl_certificate/server_name and for proxying directives: check whether proxy terminates TLS (listen 443 with ssl_certificate) or proxies TLS transparently (proxy_pass https://...). Check for proxy_ssl_server_name on upstream block.
- What the result means: If Nginx has ssl_certificate configured, it terminates TLS and must serve the correct cert. If Nginx proxies TLS to upstream with proxy_pass https:// and proxy_ssl_server_name off/default, the upstream will not receive SNI and may return a fallback cert; enabling proxy_ssl_server_name can forward SNI.
- Check hosts/DNS resolution on client and proxy (dig/host) for hostname.example.com to confirm requests go to intended proxy IP.
- What the result means: If DNS resolves to the upstream IP, client bypasses proxy and will see the upstream cert. If DNS resolves to proxy IP, but proxy still shows upstream cert, problem is proxy-side TLS handling.
Confirmed fixes
No fix has been independently verified for this scenario. Treat the causes below as diagnostic hypotheses.
Question
How do I determine whether Nginx or the upstream is presenting the wrong certificate, and what reversible changes can I make to ensure the proxy forwards SNI or terminates TLS correctly?
Verified community troubleshooting
First confirm which endpoint actually presented the certificate: run an SNI-aware TLS check (openssl s_client -connect proxy:443 -servername hostname.example.com) and note the cert SANs. If the proxy returns the wrong cert but its config has ssl_certificate, replace or point that server block to the correct cert and reload Nginx. If the upstream returns the fallback cert unless SNI is supplied, enable proxy_ssl_server_name and proxy_ssl_name in the upstream block so Nginx forwards the client hostname. Verify by repeating the s_client check and by loading the page in an incognito browser. If changes are made, keep backups of original configs and revert on failures; escalate to platform/network admin if you must touch firewall/DNS that you cannot reverse safely.
Incident analysis
Most likely causes
Summary
Suggested Fixes
Continue troubleshooting
Related troubles
Matched from the title, description and tags
- Networking42% match
TLS certificate name mismatch when proxying to upstream — why does the browser show a different certificate?
Open1 answer - Networking29% match
CORS preflight (OPTIONS) passes on localhost but fails when routed through Nginx reverse proxy — why?
Open1 answer - Networking26% match
WebSocket closes after fixed idle period when routed through Nginx reverse proxy
Open1 answer - Web Development23% match
NGINX reverse proxy returns 413 for Transfer-Encoding: chunked uploads to Next.js API while direct Node accepts them
Open0 answers - Web Development22% match
NGINX HTTP/2 proxy drops chunked Transfer-Encoding uploads to Next.js API routes — request body never reaches Node
Solved1 answer