Firefox SSL_ERROR_RX_RECORD_TOO_LONG 完全指南:根因、诊断、修复与 FAQ
Firefox 在访问 HTTPS 站点时抛出 SSL_ERROR_RX_RECORD_TOO_LONG,看起来像证书或加密算法问题,实际上绝大多数情况是协议错位:浏览器在 443 端口上说 TLS,服务端却回了明文 HTTP。本文按“含义 → 根因 → 诊断 → 修复 → 验证 → FAQ”的顺序给出可复制的命令和配置示例。
错误含义:TLS 记录头被 HTTP 响应污染
TLS 连接建立后,客户端先读 5 字节记录头:1 字节类型、2 字节版本、2 字节长度。正常类型是 0x16(握手)、0x17(应用数据)、0x15(警报)。如果服务端返回 HTTP/1.1 400 Bad Request,首字节是 H(0x48),Firefox 把后面的 TP 解释成记录长度,得到一个超大值,于是报 RX_RECORD_TOO_LONG。
所以这个错误的关键词是“收到了非 TLS 数据”,不是“证书过期”。证书问题通常报 SEC_ERROR_EXPIRED_CERTIFICATE、SSL_ERROR_BAD_CERT_DOMAIN 或 MOZILLA_PKIX_ERROR_*。
# 正常 TLS 握手开头(十六进制示意)
16 03 01 ...
# 443 端口返回明文 HTTP 时
48 54 54 50 2f 31 2e 31 ... # HTTP/1.1
头号根因:443 端口跑的是 HTTP,而不是 HTTPS
常见配置错误包括:
- Nginx 写了
listen 443;却忘记ssl,或ssl只写在另一个 server 块。 - Apache 的
<VirtualHost *:443>没有SSLEngine on,或证书指令写在错误的 VirtualHost。 - 反向代理把
proxy_pass指向http://后端:443,而后端 443 期望 TLS;或反过来用https://后端:80。 - 负载均衡或 CDN 的源站协议配成 HTTP,却连到源站 443;或目标组协议为 HTTP 但端口填 443。
- 端口被普通 HTTP 服务、调试服务或另一个站点占用。
快速判定:
curl -I --max-time 5 http://example.com:443
curl -vI --max-time 5 https://example.com
判读规则很重要:如果第一条返回普通页面、301/302 到 https、或应用 404,说明 443 在说明文 HTTP;如果返回 400 Bad Request 且正文包含 The plain HTTP request was sent to HTTPS port,反而说明 Nginx 的 443 已经启用 TLS,这是健康信号。第二条如果报 wrong version number、Empty reply from server 或 SSL_ERROR_RX_RECORD_TOO_LONG,结合第一条即可定位。
再用 OpenSSL 确认:
openssl s_client -connect example.com:443 -servername example.com
握手成功会打印证书链和 Verification: OK;失败常见 wrong version number、no peer certificate available。
五分钟诊断流程(按顺序执行)
- 确认 DNS 和监听:
dig +short example.com、ss -lntp | grep ':443'。看 443 是否被预期进程监听。 - 明文探测:
curl -I --max-time 5 http://example.com:443。区分普通 HTTP 响应与 Nginx 的 400 提示。 - TLS 探测:
curl -vI --max-time 5 https://example.com。记录wrong version number等错误。 - SNI 和证书:
echo | openssl s_client -connect example.com:443 -servername example.com 2>/dev/null | openssl x509 -noout -subject -dates。能出证书说明 TLS 层至少存在。 - 配置审计:
nginx -T | grep -n 'listen 443'或apachectl -S。检查是否缺少ssl或SSLEngine on。 - 后端协议:分别对后端执行
curl -v http://backend:443和curl -vk https://backend:443,确认哪一个是通的。 - 多节点对比:如果只有部分用户报错,逐台执行第 2、3 步,排查负载均衡节点配置漂移。
dig +short example.com
ss -lntp | grep ':443'
curl -I --max-time 5 http://example.com:443
curl -vI --max-time 5 https://example.com
nginx -T | grep -n 'listen 443'
修复 Nginx:listen 443 ssl 与反代协议必须匹配
错误示例:
server {
listen 443;
server_name example.com;
location / {
proxy_pass http://127.0.0.1:8443;
}
}
正确示例(后端是明文 HTTP):
server {
listen 443 ssl;
server_name example.com;
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
location / {
proxy_pass http://127.0.0.1:8080;
}
}
如果后端本身是 HTTPS,才写 proxy_pass https://127.0.0.1:8443;,并按需配置 proxy_ssl_server_name on;、proxy_ssl_verify on; 和信任链。不要用 http:// 去连一个只接受 TLS 的 443,也不要用 https:// 去连明文 80。
检查与重载:
nginx -T | grep -n 'listen 443'
nginx -t && nginx -s reload
注意 listen 443 ssl; 是必须的;只写 listen 443; 再加证书指令不会自动启用 TLS。新版 Nginx 可用 listen 443 ssl; 配合 http2 on;,旧版用 listen 443 ssl http2;。
修复 Apache、负载均衡与 CDN 回源
Apache 最小配置:
<VirtualHost *:443>
ServerName example.com
SSLEngine on
SSLCertificateFile /etc/letsencrypt/live/example.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem
ProxyPass / http://127.0.0.1:8080/
ProxyPassReverse / http://127.0.0.1:8080/
</VirtualHost>
验证并重载:
apachectl configtest && systemctl reload apache2
HAProxy 终止 TLS 时,bind *:443 ssl crt /etc/haproxy/certs/example.pem;后端是明文就写 server app1 10.0.0.10:8080 check,后端是 TLS 才加 ssl verify none 并连正确端口。
云负载均衡:443 监听器选 HTTPS(TLS 终止)或 TCP(透传 TLS);目标组协议必须和后端实际协议一致。目标组选 HTTP 却把端口填 443,等于让负载均衡把明文发到 TLS 端口,必然复现该错误。
CDN:源站协议选 HTTPS,并确保源站 443 真的能完成 TLS 握手;不要出现 CDN 边缘是 HTTPS、回源却用 HTTP 打到源站 443 的错配。
其他可能原因与对照表
下表按“看到的现象”快速分流。绝大多数行最终都回到同一个动作:让 443 的监听协议与客户端或上游期望一致。
| 现象 | 更可能的原因 | 验证命令 | 修复方向 |
|---|---|---|---|
curl http://host:443 返回普通页面或 301 |
443 是明文 HTTP | curl -I http://host:443 |
Nginx 加 ssl;Apache 开 SSLEngine on |
curl https://host 报 wrong version number |
TLS 客户端连到明文端口 | openssl s_client -connect host:443 |
同上,或修正 upstream 协议 |
只有 Firefox 报 SSL_ERROR_RX_RECORD_TOO_LONG,Chrome 报 ERR_SSL_PROTOCOL_ERROR |
同一协议错位的不同文案 | curl -vI https://host |
按 curl 和 OpenSSL 结果修服务端 |
curl http://host:443 返回 400 The plain HTTP request was sent to HTTPS port |
443 已是 HTTPS,客户端用错协议 | 观察响应正文 | 客户端改用 https://,不是服务端故障 |
| 部分用户或部分请求报错 | 多节点配置不一致或 CDN 回源节点错配 | 逐台 curl 和 openssl |
统一配置,滚动发布 |
Empty reply from server |
端口未监听、进程崩溃、防火墙重置 | ss -lntp | grep ':443' |
启动服务、修防火墙 |
报 SSL_ERROR_BAD_CERT_DOMAIN 或证书过期 |
证书或 SNI 问题,不是本错误 | openssl x509 -noout -subject -dates |
修证书和 SNI |
| 公司网络或代理下才出现 | 中间盒拦截 443 并返回 HTTP 错误页 | 换网络、关闭代理对比 | 调整代理或安全设备 |
真实报错与故障排查
先收集三类证据:浏览器错误、curl 输出、服务端日志。
浏览器侧:
Firefox: SSL_ERROR_RX_RECORD_TOO_LONG
Chrome: ERR_SSL_PROTOCOL_ERROR
Safari: Safari can't establish a secure connection
curl 侧(TLS 客户端连到明文端口):
$ curl -vI https://example.com
* Connected to example.com (203.0.113.10) port 443
* OpenSSL/3.0.13: error:0A00010B:SSL routines::wrong version number
curl: (35) error:0A00010B:SSL routines::wrong version number
反过来,如果 443 是明文 HTTP,用 http 探测会看到应用响应:
$ curl -I http://example.com:443
HTTP/1.1 200 OK
Server: nginx
Content-Type: text/html
如果看到 Nginx 的 400 提示,说明 TLS 已启用:
$ curl -I http://example.com:443
HTTP/1.1 400 Bad Request
Server: nginx
<html>
<head><title>400 Bad Request</title></head>
<body>
<center><h1>400 Bad Request</h1></center>
<center>The plain HTTP request was sent to HTTPS port</center>
...
OpenSSL 侧:
$ openssl s_client -connect example.com:443 -servername example.com
CONNECTED(00000003)
140736...:error:0A00010B:SSL routines::wrong version number:
...
---
no peer certificate available
Nginx 错误日志里可能出现:
[error] 123#123: *1 SSL_do_handshake() failed
(SSL: error:0A00010B:SSL routines::wrong version number)
while SSL handshaking, client: 203.0.113.10, server: 0.0.0.0:443
这条日志要结合方向判断:如果出现在面向公网的 TLS 监听器上,通常是客户端用 http:// 打了 443;如果出现在 proxy_pass https:// 的上游连接上,则是你把 HTTPS 代理到了明文后端,检查 upstream 端口和协议。
还要检查是否有另一个进程占用 443:
ss -lntp | grep ':443'
lsof -iTCP:443 -sTCP:LISTEN
如果监听进程不是 Nginx、Apache 或 HAProxy,而是某个 HTTP 调试服务,就解释了全部现象。
修复后的验证与回归测试
改完配置不要只看浏览器,按下面顺序回归:
- 配置语法:
nginx -t或apachectl configtest。 - 端口监听:
ss -lntp | grep ':443'确认是预期进程。 - TLS 握手:
openssl s_client -connect example.com:443 -servername example.com,看到Verification: OK或至少完成握手。 - HTTPS 请求:
curl -I https://example.com返回 200/301/302,而不是wrong version number。 - 明文反向探测:
curl -I http://example.com:443应返回 400 且包含The plain HTTP request was sent to HTTPS port;如果返回正常页面,说明 TLS 又丢了。 - 多节点和多地域:对每个后端 IP 执行
curl --resolve example.com:443:IP -I https://example.com。
nginx -t && nginx -s reload
ss -lntp | grep ':443'
openssl s_client -connect example.com:443 -servername example.com
curl -I https://example.com
curl -I http://example.com:443
curl --resolve example.com:443:203.0.113.10 -I https://example.com
监控建议:对 443 做 TLS 层探活(openssl 或 blackbox_exporter 的 https 探针),不要只做 TCP 端口探活。TCP 通只能证明三次握手成功,不能证明 TLS 握手成功。
FAQ
Q1:这是证书问题吗?
通常不是。证书问题会报 SEC_ERROR_EXPIRED_CERTIFICATE、SSL_ERROR_BAD_CERT_DOMAIN、MOZILLA_PKIX_ERROR_*。RX_RECORD_TOO_LONG 是记录层收到了非 TLS 数据,优先查 443 的协议。
Q2:为什么 Chrome 报 ERR_SSL_PROTOCOL_ERROR?
同一根因的不同文案。Chrome、curl、OpenSSL 对“明文 HTTP 被当成 TLS 记录”表述不同,wrong version number 是最接近底层的提示。
Q3:重启 Firefox、清缓存、换浏览器有用吗?
没用。问题在服务端或中间链路的协议配置,客户端重启不会改变 443 返回的字节。
Q4:只有部分用户遇到,怎么回事?
常见于 DNS 轮询到配置错误的后端、负载均衡节点配置不一致、CDN 回源节点错配,或公司代理和防火墙拦截 443。逐节点用 curl --resolve 和 openssl s_client 对比。
Q5:如何一句话确认 443 是 HTTPS?openssl s_client -connect 域名:443 -servername 域名 能完成握手并打印证书;或者 curl -I http://域名:443 返回 400 The plain HTTP request was sent to HTTPS port。前者更直接。
Q6:反向代理后端到底用 http:// 还是 https://?
看后端实际监听协议,不看端口号。后端 443 只接受 TLS 就用 https:// 并配置信任;后端 8080 是明文就用 http://。端口号只是数字,协议由服务端决定。
Q7:启用 HTTP/2 或 HTTP/3 会引发这个错误吗?
不会直接引发。HTTP/2 和 HTTP/3 都在 TLS 之后协商;如果 TLS 层已经把 HTTP 明文当记录读,先修 443 的 TLS 配置,再谈 ALPN 和 HTTP2。
总结:SSL_ERROR_RX_RECORD_TOO_LONG 不是证书错误,而是 443 端口协议错位的强烈信号。先用 curl -I http://域名:443 和 openssl s_client 判断 443 是否真的在说 TLS,再检查 Nginx 的 listen 443 ssl、反代 upstream 协议、负载均衡目标组和 CDN 回源协议。修完后用 HTTPS 请求和明文反向探测各验一次,才能确认 TLS 已恢复。