Hi,
I’m currently implementing Django Channels for asynchronous communication. The setup works flawlessly on my local environment, but when deployed in production (Docker container), I encounter a “connection refused” error for WebSocket connections.
Could you please review my configuration and advise on any potential issues? Your insights would be greatly appreciated.
asgi.py
"""
ASGI config for sewts_jupiter_cloud_backend project.
It exposes the ASGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/5.0/howto/deployment/asgi/
"""
import os
# from channels.auth import AuthMiddlewareStack
from channels.routing import ProtocolTypeRouter, URLRouter
# from channels.security.websocket import AllowedHostsOriginValidator
from django.core.asgi import get_asgi_application
import channel.urls
setting_evironment = os.getenv('ENVIRONMENT')
os.environ.setdefault('DJANGO_SETTINGS_MODULE',
f'sewts_jupiter_cloud_backend.settings.{setting_evironment}')
application = ProtocolTypeRouter({
"http": get_asgi_application(),
# TODO: apply allowed host check here
"websocket": URLRouter(channel.urls.websocket_urlpatterns)
})
setting
ALLOWED_HOSTS=192.168.108.76,ws://192.168.108.76
CORS_ALLOWED_ORIGINS=http://192.168.108.76:8080,http://192.168.108.76:8001,http://192.168.108.76:8000
CHANNEL_LAYERS = {
"default": {
"BACKEND": "channels.layers.InMemoryChannelLayer", # This uses an in-memory layer
"CONFIG": {},
},
}
INSTALLED_APPS = [
'daphne',
'channels',
-----