解决 Nginx 报错 upstream sent no valid HTTP/1.1 response 502
分析 Nginx 代理将 HTTP 请求转发到了 HTTPS/TCP 原始端口报 no valid response 根因,提供协议对齐与 SSL 配置方案。
问题现象
Nginx 返回 HTTP 502 Bad Gateway,错误日志记录:
2026-11-15 19:30:00 [error] 12345#12345: *67890 upstream sent no valid HTTP/1.1 response
while reading response header from upstream, client: 192.168.1.50, upstream: "http://127.0.0.1:8443/api"
触发根因
协议不匹配:Nginx 使用纯明文 HTTP 协议向一个配置了 HTTPS/TLS 加密的后端端口(如 8443)发送请求。对端直接以二进制 TLS 握手报文响应,Nginx 无法解析出标准的 HTTP 版本号。
解决步骤与操作命令
步骤一:修正 proxy_pass 协议头
若后端是 HTTPS 服务,必须使用 https:// 转发:
location /api/ {
# 修正为 https 协议
proxy_pass https://backend_ssl_pool;
proxy_ssl_server_name on;
proxy_ssl_verify off; # 内部私有证书可跳过验证
}
重载 Nginx,请求顺利返回 200。


