【发布时间】:2021-12-21 15:09:39
【问题描述】:
我正在尝试与反应前端建立套接字连接。当我使用 http API 进行连接时,它工作得非常好,但是当我尝试与 https 服务器连接时,我得到了连接失败的错误。
这是我要连接的反应代码:
import io from "socket.io-client";
const CONNECTION_PORT = 'https://socket.abcd.com/api' // (I did reverse proxy in nginx for /api endpoint) which is not connecting. I also have SSL certificate purchased for this API. Whereas,
const CONNECTION_PORT = 'http://localhost:5000'. // this works perfectly fine.
useEffect(() => {
socket = io(CONNECTION_PORT, {
transports: ["websocket"],
});
});
有人遇到同样的问题吗?请让我知道有什么办法可以解决这个问题。
【问题讨论】:
-
这完全取决于您定义代理 (nginx) 的方式