channels: It does not work on production server!
Hello! I do like channels - it is good solution. I wrote a small application with channels - it works fine on localhost (without any problems).
Options:
- Django 1.10
- Linux Debian 8.5
- Python 3.4
But problems arose when deploying: In my settings.py
...
INSTALLED_APPS = [
...
'channels',
...
]
...
CHANNEL_LAYERS = {
'default': {
'BACKEND': 'asgi_redis.RedisChannelLayer',
'CONFIG': {'hosts': [('localhost', 6379), ], },
'ROUTING': 'basic.channels.routing',
},
}
...
I will repeat - it works fine on localhost!!!
For deploy i create asgi.py
:
import os
from channels.asgi import get_channel_layer
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'basic.settings')
application = get_channel_layer()
Previously, I run gunicorn
used wsgi.py
, but now I stopped gunicorn
and run daphne
:
$ daphne -b 0.0.0.0 -p 3355 basic.asgi:application
and workers:
$ ./manage.py runworker
The site runs and works fine! But the page with socket has an error:
WebSocket connection to 'ws://example.com/some/path/' failed: Unexpected response code: 200
I do not know - how to solve this problem? Please, show me your settings, and method that you run the Django project!
P.p.s Redis work too, I use redis for session and for page view count (port/host are correct).
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 2
- Comments: 20 (5 by maintainers)
You must run two processes in production (runserver combines these for you normally):
daphne -b 0.0.0.0 -p 8001 yourproject.asgi:channel_layer
- The webserver that receives connections. Point Nginx to this. More docs here: https://github.com/django/daphnemanage.py runworker
- The Django worker. You can run as many of these as you like; they connect to Daphne via the channel layer.You also need to not be using the in-memory channel layer.
Have you started the workers as well? You start them via
manage.py runworker
@proofit404 I’ll make my project as small as I can so that it can be reproduced on a local machine, doing…
port must be in range 0-65535.