Skip to main content
 首页 » 编程设计

nginx之如何强制 Nginx 针对上游服务器 block 中存在的主机名验证上游证书

2025年05月04日251grandyang

我正在尝试在代理路径的每一层实现 HTTPS 协议(protocol)通信。我的代理路径是从客户端到负载均衡器(nginx),然后从 nginx 到上游服务器。

当请求从 nginx 代理到上游服务器时,我遇到了问题。

我在 nginx 日志中收到以下错误

2017/03/26 19:08:39 [error] 76753#0: *140 upstream SSL certificate does not match "8ba0c0da44ee43ea894987ab01cf4fbc" while SSL handshaking to upstream, client: 10.191.200.230, server: abc.uscom-central-1.ssenv.opcdev2.oraclecorp.com, request: "GET /a/a.html HTTP/1.1", upstream: "https://10.240.81.28:8001/a/a.html", host: "abc.uscom-central-1.ssenv.opcdev2.oraclecorp.com:10003" 

这是我对上游服务器 block 的配置
upstream 8ba0c0da44ee43ea894987ab01cf4fbc { 
                            server slc01etc.us.oracle.com:8001 weight=1; 
                    keepalive 100; 
} 
 
proxy_pass https://8ba0c0da44ee43ea894987ab01cf4fbc; 
proxy_set_header Host $host:10003; 
proxy_set_header WL-Proxy-SSL true; 
proxy_set_header IS_SSL ssl; 
proxy_ssl_trusted_certificate /u01/data/secure_artifacts/ssl/trusted_certs/trusted-cert.pem; 
proxy_ssl_verify on;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 

当请求从 Nginx 发送到上游服务器时,nginx 会将上游 ssl 证书与 proxy_pass 指令中存在的模式进行匹配。但我的上游 ssl 证书模式是上游服务器主机名 (slc01etc.us.oracle.com) 。

有什么办法可以强制 Nginx 针对上游服务器 block 中提供的服务器主机名验证上游 ssl 证书,而不是 proxy_pass 指令中存在的模式?

请您参考如下方法:

我们可以在 nginx 中使用“proxy_ssl_name”指令。它允许覆盖 nginx 验证后端服务器证书的主机名。

proxy_ssl_name mybackend-server.hostname.com;