我有一个使用 Django 和 Django Channels 的简单聊天应用程序。我正在关注 Django Channels 教程。它在本地运行良好,但在生产中却失败了。
这是我打开 websocket 的 JavaScript 代码:
const chatSocket = new WebSocket(
'ws://'
+ window.location.host
+ '/ws/chat/'
+ roomName
+ '/'
);
这是进入聊天页面时出现的错误:
Mixed Content: The page at 'https://site-url.ir/chat/room/1/' was loaded over HTTPS, but attempted to connect to the insecure WebSocket endpoint 'ws://site-url.ir/ws/chat/room_1/'. This request has been blocked; this endpoint must be available over WSS.
room.js:18 Uncaught DOMException: Failed to construct 'WebSocket': An insecure WebSocket connection may not be initiated from a page loaded over HTTPS.