【发布时间】:2019-07-09 14:29:42
【问题描述】:
我想使用 nginx 作为 websocket 连接的反向代理。
考虑将 echo.websocket.org 作为我的后端 websocket 服务。作为测试客户端,我使用来自https://github.com/websockets/wscat 的wscat。
什么有效:
客户端 后端:
wscat --connect ws://echo.websocket.org
客户端 :wscat --connect wss://echo.websocket.org
客户端 代理 后端:wscat --connect ws://localhost 使用以下 nginx 配置:
events {
}
http {
server {
listen 80;
location / {
proxy_pass http://echo.websocket.org;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection upgrade;
}
}
}
客户端 代理 后端:wscat -n --connect wss://localhost 使用以下 nginx 配置:
events {
}
http {
server {
listen 443 ssl;
ssl_certificate /pki/cert.pem;
ssl_certificate_key /pki/key.pem;
location / {
proxy_pass http://echo.websocket.org;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection upgrade;
}
}
}
我想要并且需要帮助的是配置 nginx 以使用安全的 websocket 连接到后端。我想要这个配置:
客户端 代理 后端
我尝试将http://echo.websocket.org 更改为https://echo.websocket.org,但没有成功。这会导致 504 网关超时。
【问题讨论】:
-
我认为您缺少代理 SSL 证书设置。看看
proxy_ssl_certificatedocumentation 和Securing HTTP Traffic to Upstream Servers guide...它应该(可能)也可以与WebSockets 一起使用。 -
我不知道周五和今天之间发生了什么变化,但它现在正在工作,没有任何改变。无论如何,谢谢你让我再试一次:D
-
我很高兴它的工作:)
-
@merl 请查看示例,可能证书或域信息昨天没有更新,我可能对你有用