Nginx Upstream TLS Verification
Two connections, two trust decisions
When Nginx terminates HTTPS and proxies to an application, the browser checks the frontend certificate. Nginx is a separate client of the backend. A browser padlock proves nothing about the backend transport or authentication. In this example both legs use TLS, with explicitly configured trust.
Browser -- TLS A: edge.test --> NginxNginx -- TLS B: origin.test --> backendEach connection has its own identity, keys and policy.Verify the backend certificate and name
Using https in proxy_pass requests encrypted transport, but upstream certificate verification is disabled by default in Nginx. Turn verification on and configure a PEM trust bundle. A valid chain alone is insufficient: the presented identity must match the expected upstream name. If connecting to an IP address or an upstream group, set the intended DNS identity explicitly. SNI helps the upstream select its certificate; it does not itself authenticate that certificate.
location / { proxy_pass https://127.0.0.1:9444; proxy_ssl_verify on; proxy_ssl_trusted_certificate certs/server-ca.crt; proxy_ssl_name origin.test; proxy_ssl_server_name on; proxy_ssl_protocols TLSv1.2 TLSv1.3; proxy_set_header Host origin.test;}The socket destination is 127.0.0.1:9444 while the authenticated service identity is origin.test. The backend HTTP Host value is also set deliberately, but HTTP Host and TLS SNI are independent. The expected successful response in the staged lab is origin-ok. The trust bundle is private to the lab and must be replaced with approved trust anchors for real deployments. A chain with intermediates may need an appropriate verification depth.
Diagnose failed upstream authentication
openssl verify -CAfile certs/server-ca.crt -purpose sslserver \ -verify_hostname origin.test certs/origin.crtThe offline command should report OK for the generated origin certificate. It verifies a stored certificate, not a network connection. Change the expected name to wrong.test and verification should fail. A different CA should also fail. An upstream handshake or verification failure normally becomes a proxy failure (often 502 in this single-upstream fixture); review the error log and preserve the failure rather than bypassing verification.
curl --noproxy "*" --cacert certs/server-ca.crt \ --resolve origin.test:9444:127.0.0.1 https://origin.test:9444/This direct request uses the expected hostname while resolving it to loopback. Compare it with the frontend request. If the direct request works but the proxied request fails, inspect the proxy trust bundle, verification name, SNI and chain. Do not use disabled verification as a fix. Limit the proxy target to an approved fixed service; never derive trust settings or upstream identity from arbitrary request headers.
Practice
For a correct CA and name, correct CA but wrong name, and wrong CA with correct name, predict certificate verification outcomes. Then explain which connection a browser verifies. Sources: https://nginx.org/en/docs/http/ngx_http_proxy_module.html; https://docs.openssl.org/3.5/man1/openssl-verification-options/.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Nginx Upstream TLS Verification
Secure the second TLS connection from Nginx to a backend using a trusted CA, expected name and SNI.
What does a valid browser-facing certificate establish about the upstream?
Which directive enables upstream certificate checks?
What should proxy_ssl_name contain for a fixed IP with certificate origin.test?
What does an offline openssl verify command establish?
What is the safe response to a name mismatch?