django - Django 频道使用 WS:// 但不使用 WSS://
问题描述
我遵循了django-channels 教程中的解释,并且能够在本地运行聊天。
但是,它在生产中不起作用。
这是调试器的输出:
WebSocket connection to 'wss://www.example.com/ws/chat/lobby/' failed: Error during WebSocket handshake: Unexpected response code: 404
(anonymous) @ (index):23
(index):40 Chat socket closed unexpectedly
chatSocket.onclose @ (index):40
(index):56 WebSocket is already in CLOSING or CLOSED state.
document.querySelector.onclick @ (index):56
document.querySelector.onkeyup @ (index):47
这是我用来尝试让它与我们的 https 网站一起使用的 javascript:
const roomName = JSON.parse(document.getElementById('room-name').textContent);
var loc = window.location;
var wsStart = 'ws://';
if (loc.protocol === 'https:') {
wsStart = 'wss://'
}
const chatSocket = new WebSocket(
wsStart
+ window.location.host
+ '/ws/chat/'
+ roomName
+ '/'
);
我将 redisgreen 用于 redis :
CHANNEL_LAYERS = {
'default': {
'BACKEND': 'channels_redis.core.RedisChannelLayer',
'CONFIG': {
"hosts": [('redis://:xxxxxxx@great-whale-0077a76ca7.redisgreen.net:11042/')]
},
},
}
其余代码按照教程。
我不确定我应该如何解决这个问题。有什么线索吗?是否需要实施 Daphne 才能在生产中运行渠道?还是我做错了什么?
非常感谢你的帮助。
解决方案
推荐阅读
- javascript - 如何使用`axios`发布原始数据
- python - 另一个 python 调用时无法正确设置 Tkinter 的变量
- ms-access - Microsoft Access - 使用多个组合框设置报告
- regex - 在 Python 中查找 http 链接并放在标签之间?
- mysql - 连接超时错误
- node.js - 无法修复 - events.js:183 throw er; // 未处理的“错误”事件
- jquery - 为什么单击子元素时会触发鼠标离开
- c++ - 通过 C++ 模板元编程从数组名推导出数组维数
- android - 在安装下载的 apk 文件时通过 Intent.getData() 错误暴露在应用程序之外
- php - 将 Symfony 项目部署到 App Engine - 错误:文件过多