【发布时间】:2020-03-04 18:45:43
【问题描述】:
当我尝试使用sslserver 运行 Django 应用程序时,如下所示,
python manage.py runsslserver
错误:
追溯:
Validating models...
System check identified no issues (0 silenced).
November 08, 2019 - 11:17:26
Django version 2.0.7, using settings 'dashboard_channels.settings'
Starting development server at https://127.0.0.1:8000/
Using SSL certificate: \lib\site-packages\sslserver\certs\development.crt
Using SSL key: \lib\site-packages\sslserver\certs\development.key
Quit the server with CTRL-BREAK.
[08/Nov/2019 11:18:33] "GET / HTTP/1.1" 200 1299
[08/Nov/2019 11:18:34] "GET / HTTP/1.1" 200 1299
[08/Nov/2019 11:18:35] "GET /static/js/jquery.js HTTP/1.1" 200 270575
Not Found: /ws/home
[08/Nov/2019 11:18:36] "GET /ws/home HTTP/1.1" 404 2134
浏览器控制台:
(index):31 WebSocket connection to 'wss://127.0.0.1:8000/ws/home' failed: Error during WebSocket handshake: Unexpected response code: 404
(index):41 error Event
(index):44 close CloseEvent
代码:
Javascript:
var loc = window.location;
var wsStart = 'ws://';
if (loc.protocol == 'https:') {
wsStart = 'wss://'
}
var endpoint = wsStart + loc.host + '/ws/home';
var socket = new WebSocket(endpoint);
使用python manage.py runserver 命令可以正常工作,这意味着http 可以正常工作,但不能使用https。
如何解决这个问题? (如何调试才能解决这个问题?)
还有其他方法可以在https 门户上部署 WebSockets 吗?
仍然面临这个问题。有人可以帮忙吗?
无论如何这是为了测试目的,最后,我需要将它部署在windows server机器上的Apache2.4上。我已经为https 设置了,但没有为网络套接字设置。
【问题讨论】:
-
它说 Not Found: /ws/home。 http 也一样吗?
-
不,它工作正常。
http没有问题。 -
@shaikmoeed 请检查您是否在 settings.py 中配置了 CHANNEL_LAYERS
-
@wowkin2
CHANNEL_LAYERS已配置并且与http完全兼容。如何在https上运行? -
@shaikmoed 你试过用达芙妮吗?如果没有 - 真的建议这样做:github.com/django/daphne
标签: javascript python ssl websocket wss