B
B
bubaley2021-08-18 02:15:19
Django
bubaley, 2021-08-18 02:15:19

Django. What is better to use with nginx: daphne or gunicorn+uvicorn and how to use it correctly?

Hello, I want to properly deploy a django project in a production environment in docker. But there are a number of questions that have been terrorizing me for several days.

1. When using django-channels, which is better to use gunicorn+uvicorn or daphne?
- When using uvicorn, I specify workers for multithreading. Daphne doesn't have this, doesn't she need it, or should it be used in some other way?
- When deploying with daphne, images are not loaded, because http requests come to django through daphne (the browser starts to swear, they are not loaded at all in mobile phones). The doc says that you need to specify ssl certs for everything to start, but this is all inside the docker, I don’t know how to forward it correctly (certs outside the docker) and whether it should be done (in uvicorn you can just specify --forwarded-allow-ips= "*" and everything becomes ok).

2. Is it necessary to separate the websocket application as asgi and regular wsgi into different containers? On the Internet, I found a couple of examples when they do this, but I can’t understand why, because in the asgi file, you can split them using the ProtocolTypeRouter.

3. Why push inside the nginx container if it still needs to be on the server to catch incoming requests. It turns out the chain nginx -> nginx -> asgi-server. I thought that you can safely get rid of nginx within the container. Especially if the machine is not 1 project but a couple.

4. When working in containers, do I need to use a .sock file, or can I directly proxy requests to the container with django on the specified port? Why is it needed at all?

Of course, there are many questions, but they are very important for me.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2021-08-18
@bubaley

When using django-channels, which is better to use gunicorn+uvicorn or daphne?

Daphne only.
Daphne doesn't have this, doesn't she need it, or should it be used in some other way?

Because it's asynchronous.
When deploying with daphne, images are not loaded, because http requests come to django through daphne

Requests to static should be handled by Nginx.
Why push inside an nginx container

No need. There should be one thing in the container, this is their essence.
When working in containers, do I need to use a .sock file, or can I directly proxy requests to the container with django on the specified port? Why is it needed at all?

Not necessary. This is a unix socket .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question