![Nginx 上游 wss 代理 SSL_read() 失败(SSL:错误:0A000126:SSL 例程::读取时出现意外的 eof)](https://linux22.com/image/784287/Nginx%20%E4%B8%8A%E6%B8%B8%20wss%20%E4%BB%A3%E7%90%86%20SSL_read()%20%E5%A4%B1%E8%B4%A5%EF%BC%88SSL%EF%BC%9A%E9%94%99%E8%AF%AF%EF%BC%9A0A000126%EF%BC%9ASSL%20%E4%BE%8B%E7%A8%8B%3A%3A%E8%AF%BB%E5%8F%96%E6%97%B6%E5%87%BA%E7%8E%B0%E6%84%8F%E5%A4%96%E7%9A%84%20eof%EF%BC%89.png)
我需要的是
Client <--wss---> nginx <--wss--> server
我正在做一个 wss 代理,我已经让它在 Apache 上运行了,但是现在我想切换到 nginx,这里是 apache 配置:
<LocationMatch "/statistics">
ProxyPass wss://127.0.0.1:23456
ProxyAddHeaders Off
ProxyPreserveHost On
RequestHeader set Host %{HTTP_HOST}s
RequestHeader set X-Forwarded-For %{REMOTE_ADDR}s
</LocationMatch>
在 nginx 上我使用这个配置/etc/nginx/nginx.conf
server {
listen 444 ssl;
listen [::]:444 ssl;
server_name domain.com www.domain.com;
root /usr/share/nginx/html;
ssl_certificate "/etc/letsencrypt/live/domain/fullchain.pem";
ssl_certificate_key "/etc/letsencrypt/live/domain/privkey.pem";
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 10m;
ssl_ciphers PROFILE=SYSTEM;
ssl_prefer_server_ciphers on;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
proxy_ssl_server_name on;
ssl_protocols TLSv1.2 TLSv1.3;
location /statistics {
proxy_pass https://127.0.0.1:23456;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $host;
proxy_ssl_name $host;
proxy_ssl_session_reuse off;
proxy_ssl_certificate "/etc/letsencrypt/live/domain/fullchain.pem";
proxy_ssl_certificate_key "/etc/letsencrypt/live/domain/privkey.pem";
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
我的网站在 Nginx 上加载正常,没有任何 SSL 错误,不起作用的是带有 wss 的 websocket,带有 ws 的 websocket 也可以正常工作!
我用来wscat
测试运行的连接:
wscat -c wss://kaveneger.ir:23456
Connected (press CTRL+C to quit)
>
意味着我的端点很好(实际上不需要这个测试,因为它在 Apache 中工作,但无论如何......)
下面是我使用 nginx 执行的操作
wscat -c wss://domain.com:444/statistics
error: Unexpected server response: 404
> %
Nginx 日志
/var/log/nginx/access.log
123.123.123.123 - - [27/Feb/2023:21:53:15 +0000] "GET /statistics HTTP/1.1" 404 0 "-" "-" "-"
/var/log/nginx/error.log
2023/02/27 21:53:49 [crit] 70632#70632: *14 SSL_read() failed (SSL: error:0A000126:SSL routines::unexpected eof while reading) while keepalive, client: 123.123.123.123, server: 0.0.0.0:444
我的操作系统是 Rocky Linux 9 和 nginx 版本:nginx/1.20.1
我已经搜索了很多次并尝试了所有找到的解决方案但没有任何效果!
更新
如果我使用location /
而不是,它就会起作用location /statistics
!