要让Nginx严格校验上游微服务TLS证书,必须同时配置proxy_ssl_verify on、proxy_ssl_trusted_certificate、proxy_ssl_name和proxy_ssl_server_name on四项指令,缺一不可且须同在location或upstream块内;此外建议补充proxy_ssl_verify_depth 3、proxy_ssl_protocols TLSv1.2 TLSv1.3及proxy_ssl_session_reuse off以增强安全性与稳定性。
要让 Nginx 负载均衡网关真正严格校验上游微服务节点返回的 TLS 证书,不能只写 proxy_ssl_verify on。必须四点齐备、协同生效,否则会静默降级或直接返回 502 错误。
这四项缺一不可,且需全部写在 location 或 upstream 块内(http 或 server 块中声明无效):
仅配齐四项还不够,以下配置能覆盖常见生产场景:
proxy_ssl_trusted_certificate 所指文件必须满足:
-----BEGIN CERTIFICATE----- 开头、-----END CERTIFICATE----- 结尾/etc/nginx/ssl/upstream-ca.crt
openssl pkcs7 -print_certs -in /path/to/file.crt -noout 能正常输出即为合法配置重载后,不能只看 Nginx 启动成功:
certificate verify failed,说明某项配置缺失或不匹配error_log /var/log/nginx/error.log debug;,查看 TLS 握手细节(注意生产环境慎用)SSL_do_handshake() failed 或 unable to get issuer certificate 等线索