I have been running my beginner Django projects with manage.py runserver
. I see suggestions to use gunicorn
instead. What is the difference ?
Gunicorn is a WSGI server This way, when coding up your a Django application you don't need to find your own solutions for: communicating with multiple web servers. reacting to lots of web requests at once and distributing the load. keepiung multiple processes of the web application running.
Django's primary deployment platform is WSGI, the Python standard for web servers and applications. Django's startproject management command sets up a minimal default WSGI configuration for you, which you can tweak as needed for your project, and direct any WSGI-compliant application server to use.
Both can reach very impressive levels of performance, though some have mentioned that Gunicorn works better under high load. Drawbacks to Gunicorn are much the same as uWSGI, though I personally have found Gunicorn to be more easily configurable than uWSGI.
Django uses their own web server, which is not supposed to be used in a production setting. DO NOT USE THIS SERVER IN A PRODUCTION SETTING.
nginx and gunicorn are probably the most popular configuration for production deployments. Before detailing why gunicorn is recommended over runserver, let's quickly clarify the difference between nginx and gunicorn, because both state that they are web servers.
NGINX should be your entrance point to the public, it's the server listening to port 80 (http) and 443 (https). Its main purpose is handling HTTP requests, that is applying redirects, HTTP Auth if required, managing TSL/SSL Certificates and - among other things - decides where your requests is finally going to. E.g. there maybe a node.js app living on localhost:3000
that awaits requests on/foo/api
while gunicorn is waiting at localhost:8000
to serve your awesome app. This functionality of proxying incoming requests to so called upstream
services (in this case node.js and gunicorn) is called reverse-proxy.
GUNICORN is a server that translates HTTP requests into Python. WSGI is one of the interfaces/implementations that does that (e.g., the text parts of http headers are transformed into key-value dicts).
Django's built-in development web server (what you get when you run manage.py runserver
) provides that functionality also, but it targets a development environment (e.g., restart when the code changes), whereas Gunicorn targets production.
Gunicorn has many features that Django's built-in server is lacking:
There are web servers other than gunicorn, but gunicorn (inspired by ruby's unicorn) is very popular and easy to setup, and hence is not only a good starting point, but a professional solution that is used by large projects.
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