我有一个应用程序位于具有配置的Django服务器中。现在我也必须一起工作。在本地计算机上一切都很好,但我读过很多关于 Django Channels 与 uwsgi 不兼容的内容。NginxuwsgiDjango Channels
nginx.conf我尝试多次以多种不同的方式配置代理,Daphne但对我来说没有任何作用。我有这个问题几个月了,但我找不到任何可以帮助我的东西。
设置.py
# WSGI
WSGI_APPLICATION = 'config.wsgi.application'
# Channels
ASGI_APPLICATION = 'config.routing.application'
CHANNEL_LAYERS = {
'default': {
'BACKEND': 'channels_redis.core.RedisChannelLayer',
'CONFIG': {
"hosts": [('127.0.0.1', 6379)],
},
},
}
Run Code Online (Sandbox Code Playgroud)
配置.路由.py
from channels.auth import AuthMiddlewareStack
from channels.routing import ProtocolTypeRouter, URLRouter
import myproject.websocket.routing
application = ProtocolTypeRouter({
'websocket': AuthMiddlewareStack(
URLRouter(
myproject.websocket.routing.websocket_urlpatterns
)
)
})
Run Code Online (Sandbox Code Playgroud)
网络套接字网址
from django.urls import re_path
from . import consumers
websocket_urlpatterns = [
re_path(r'ws/socket/$', consumers.WebSocketConsumer),
]
Run Code Online (Sandbox Code Playgroud)
阿斯吉 …