There are 3 ways to run a django application with gunicorn:
Standard
gunicorn
+wsgi
(ref django doc)gunicorn project.wsgi:application
Using gunicorn django integration (ref gunicorn doc and django doc):
python manage.py run_gunicorn
Using
gunicorn_django
command (ref gunicorn doc)gunicorn_django [OPTIONS] [SETTINGS_PATH]
Django's documentation suggests using 1., which is not even listed as an option on Gunicorn documentation.
Is there any best practice on the best way to run a django app with gunicorn, and what are the foreseable advantages/disadvantages of these different solutions?
Taking a glimpse at gunicorn's code it looks like they pretty much all do the same: 2. seems to be creating a wsgi app using django's internals, and 3. uses 2.
If that's the case, I wouldn't even understand what's the reason for not simply using "1." all the time, especially since a wsgi.py
file is autocreated for you since django 1.4; if that's true maybe simply a documentation improvement should be suggested...
Also, best practice for gunicorn settings with django would be great. Using 1., does it make sense to set some defaults in the wsgi file and avoid additional settings?
References:
- Should I use django-gunicorn integration or wsgi? only concerns choices 1. and 3., there's no hint for the settings and the answer gives no rationale
- Deploying Django with gunicorn and nginx give some broader information but is not strictly related nor answer this question
- Django Gunicorn wsgi about version "4", which is launching
gunicorn -c configfile
and configfile will point to django_settings to django - Django WSGI and Gunicorn is just a bit confusing :) mixing up 1. and 3. Of course
wsgi.py
is used only with 1.