3

This might be really stupid question; I'm trying to deploy Django application using Gunicorn. However, I just created wsgi.py which looks like below (wsgi.py is in my root project folder):

import os

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myproject.settings")

# This application object is used by any WSGI server configured to use this
# file. This includes Django's development server, if the WSGI_APPLICATION
# setting points here.
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

# Apply WSGI middleware here.
# from helloworld.wsgi import HelloWorldApplication
# application = HelloWorldApplication(application)

and now I ran:

python manage.py run_gunicorn

Will Gunicorn automatically picks up this wsgi.py? How does this work? (not sure what wsgi is doing). Or do i need to specify something?

CIF
  • 1,754
  • 2
  • 18
  • 30

2 Answers2

2

If you have gunicorn listed in INSTALLED_APPS of Django settings module, the command is:

python manage.py run_gunicorn

Not the command you give.

Graham Dumpleton
  • 57,726
  • 6
  • 119
  • 134
  • Thanks for pointing out. That was just a typo. However, my question was how does gunicorn picks up wsgy.py.. ? – CIF Aug 22 '12 at 17:28
  • It doesn't. When you add 'gunicorn' to INSTALLED_APPS it adds the run_gunicorn management command you run it and as far as I know it completely ignores the wsgi.py file. The wsgi.py file is only used by WSGI servers that want a direct WSGI script file. You could technically run 'gunicorn wsgi:application' directly and avoid the management command in which case it would use it, but you may have to set up extra paths in PYTHONPATH for environment so it knows where to find stuff. – Graham Dumpleton Aug 23 '12 at 00:11
  • Easy way to find out. Rename it and run the command. If it errors you do need it, but my understanding is that run_gunicorn management command doesn't use it. – Graham Dumpleton Aug 23 '12 at 03:50
  • Thanks a bunch! Now I'm getting this error: http://stackoverflow.com/questions/12084673/gunicorn-loading-static-file – CIF Aug 23 '12 at 04:41
1

I have Gunicorn to host my django site and this is the config details hope this is helpfull

Community
  • 1
  • 1
Rakesh
  • 81,458
  • 17
  • 76
  • 113
  • why do we need nginx here? Can't we just run gunicorn for port 80? bit confused why we need additional server inbetween. – CIF Aug 22 '12 at 16:16
  • could you explain whats the benefit using nginx here? – CIF Aug 22 '12 at 16:17
  • gunicorn is an HTTP/WSGI server designed to serve fast clients or sleepy applications. That is to say, behind a buffering front-end server such as nginx – Rakesh Aug 23 '12 at 05:02
  • Still not convinced why we should combine using with NGINX. I have very short knowledge in servers. – CIF Aug 23 '12 at 17:17
  • It's preferable to use Nginx to serve your static files, and pass non-static requests to gunicorn. This is because Nginx is quite fast at serving static files. Also, if you use Nginx, you can run a single Django server on port 80 that serves both HTTP and HTTPS. – Dustin Rasener Mar 14 '13 at 02:02