我已经设置了我的Django服务器在https模式下运行,API调用也正常工作。我还配置了Daphne,它启动时没有任何问题。但是,当我尝试使用wss打开安全的WebSocket连接时,它失败了。
如果我能在这方面得到任何帮助就太好了。谢谢。
docker-compose。YML
services:
api:
platform: linux/amd64
container_name: api
build:
context: .
dockerfile: Dockerfile.dev
command: 'sh -c "./manage.py migrate && python manage.py runsslserver 0.0.0.0:8080"'
restart: always
networks:
- default
volumes:
- ./:/app
- $HOME/.aws:/root/.aws:ro
- /var/run/docker.sock:/var/run/docker.sock
- type: bind
source: ./docker/cpuinfo_with_fake_speed.txt
target: /proc/cpuinfo
ports:
- 8080:8080
env_file:
- ./.env
depends_on:
- db
daphne:
platform: linux/amd64
container_name: daphne
build:
context: .
dockerfile: Dockerfile.dev
command: 'sh -c "daphne --ws-protocol [ws, wss] -v 1 -e ssl:8000:privateKey=key.pem:certKey=cert.pem apps.asgi:application"'
restart: always
working_dir: /app
networks:
- default
volumes:
- ./:/app
- /var/run/docker.sock:/var/run/docker.sock
ports:
- 8000:8000
www.example.com
django_asgi_app = get_asgi_application()
from channels.routing import ProtocolTypeRouter, URLRouter
application = ProtocolTypeRouter(
{
"http": django_asgi_app,
"websocket": AuthMiddlewareStack(URLRouter([path('ws/notifications/', NotificationConsumer.as_asgi())])),
}
)
我看到达芙妮的服务启动正常
daphne | 2023-04-28 05:39:32,845 INFO Starting server at ssl:8000:privateKey=key.pem:certKey=cert.pem
daphne | 2023-04-28 05:39:32,847 INFO HTTP/2 support enabled
daphne | 2023-04-28 05:39:32,847 INFO Configuring endpoint ssl:8000:privateKey=key.pem:certKey=cert.pem
daphne | 2023-04-28 05:39:32,891 INFO Listening on TCP address 0.0.0.0:8000
这是如何,我试图打开WebSocket连接,失败了。
wss://localhost:8000/ws/notifications/?userid=x48
1条答案
按热度按时间ua4mk5z41#
显然我使用了一个错误的客户端来测试安全的websockets。Chrome扩展饼插座工作得很好。