best way for deployment of django-channels in real server

Viewed 1201

I have a website written with django and use django-channels. I can test this with "manage.py runserver" and it's work fine.

But in real world you can't use this method to run your website. Apache and Nginx are not serving django-channels (Websocket) and you should use alongside server s.a. Daphne but it's very complicated to config this approach. and i can do this for one time and forget that :(

I'm locking for the best approach to deployment django-channels app in real world.

thanks.

2 Answers

For production, we should use webservers like Nginx or Apache to server. Since these servers doesn't have ASGI support, we have to use ASGI servers like daphne or uvicorn.

Install daphne or uvicorn and start a process with

uvicorn avilpage.asgi --log-level critical --workers 4

or

daphne avilpage.asgi:application --bind 0.0.0.0 --port 9000 --verbosity 1

This will start a separate process to serve ASGI requests ie WebSockets. From here we can follow the same process as deploying a normal HTTP web application.

I have written a blog post on deploying channels to production.

Related