Nginx reverse proxy error: SSL alert number 40 while SSL handshaking to upstream server (SSL server name)
原因
当使用 Nginx 位置的proxy_pass使用上游时,它(大部分)开箱即用。但是,随着互联网(及其安全设置)变得越来越复杂,现在可能会出现意想不到的SSL错误
现象
当现在使用浏览器或 curl 访问此位置时,Nginx 将返回 502 错误。仔细查看此域中的调试错误日志会发现,存在 SSL 警报编号为 40 的 SSL 握手错误,导致上游服务器不可用:

2024/02/18 16:38:21 [error] 80797#0: *16 SSL_do_handshake() failed (SSL: error:0A000410:SSL routines::ssl/tls alert handshake failure:SSL alert number 40) while SSL handshaking to upstream, client: 127.0.0.1, server: localhost, request: "GET / HTTP/1.1", upstream: "https://172.xxx.xxx.xxx:443/", host: "localhost:8080"
2024/02/18 16:38:21 [error] 80797#0: *16 SSL_do_handshake() failed (SSL: error:0A000410:SSL routines::ssl/tls alert handshake failure:SSL alert number 40) while SSL handshaking to upstream, client: 127.0.0.1, server: localhost, request: "GET / HTTP/1.1", upstream: "https://172.xx.xxx.xxx:443/", host: "localhost:8080"
解决方案
To tell Nginx that the (original) server name (the upstream domain itself) should be used, a specific parameter proxy_ssl_server_name can be added:
server {
listen 8080;
server_name localhost;
location / {
root /opt/homebrew/var/www;
index index.html index.htm;
#告诉 Nginx 使用正确的 SSL 服务器名称
proxy_ssl_server_name on;
proxy_pass https://taobao.com/;
}
}
然后重启nginx即可
查看nginx配置信息,代理配置位置及日志位置
nginx -V 2>&1
启动nginx 服务的命令是:
nginx
启动 nginx 服务。如果您已经配置了 nginx 并且需要重新加载配置而不重启服务,可以使用以下命令:
nginx -s reload
要停止 nginx 服务,可以运行:
nginx -s stop
注意,这些命令可能需要以管理员身份来执行它们。

浙公网安备 33010602011771号