Typical setups I've found on Google to run a django application on AWS all suggest a setup like
ELB -> nginx -> gunicorn -> django
I was wondering why the nginx part is really needed here? Isn't ELB sufficient as proxy?
In our case, we are running multiple Gunicorn/django instances in individual docker containers on ECS.
Nginx and Gunicorn work togetherGunicorn translates requests which it gets from Nginx into a format which your web application can handle, and makes sure that your code is executed when needed. They make a great team! Each can do something, which the other can't.
It depends on the rest of your architecture. If ALB can handle everything for you, you probably don't need nginx. Also, nginx has a learning curve in case you are a first time user.
A year later, AWS launched Network Load Balancer for improved Layer 4 load balancing, so the set of choices for users running highly available, scalable applications on AWS includes: NGINX Open Source and NGINX Plus. Classic Load Balancer.
Nginx is a web server and reverse-proxy responsible for serving static content, gzip compression, ssl, proxy_buffers and other HTTP stuff while gunicorn is a Python HTTP server that interfaces with both nginx and your actual python web-app code to serve dynamic content.
Without Nginx, It would work just fine and you will still be safe from the majority of DDOS attacks that can bring down an exposed gunicorn server.
I can only see Nginx helpful to add to the stack if it'll be serving your static files. However, it's much better to serve your static files by S3 (+ cloudfront as a bonus) since it's has high availability and reliability baked in.
Sources: http://docs.gunicorn.org/en/latest/deploy.html#nginx-configuration https://stackoverflow.com/a/12801140
I had to search a lot to get a satisfying answer :
Additionally, even in Gunicorn's documentation, it is recommended to use Nginx in front of it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With