Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Deploying Django

Brian Riley
February 22, 2012
840

Deploying Django

Presenting my setup at LA Django Meetup Feb. 21, 2012.

Brian Riley

February 22, 2012
Tweet

Transcript

  1. WHO AM I? • been working with Django since 2006

    • put Django into production many times, using just about every setup • work at EdgeCast
  2. DEPLOYING IS CONFUSING • gunicorn or uwsgi • nginx or

    apache • ? or ? or, you could just use Heroku
  3. THE STACK: WEB SERVER • serving static media files •

    proxying to dynamic applications “nginx is an HTTP and reverse proxy server”
  4. NGINX CONF server { listen 80 default; server_name example.com; location

    /static/ { root /path/to/project; } location / { proxy_pass http://127.0.0.1:8000; } }
  5. THE STACK: WSGI SERVER “Gunicorn 'Green Unicorn' is a Python

    WSGI HTTP Server for UNIX” ./manage.py run_gunicorn
  6. UPSTART • comes with Ubuntu • automates startup/shutdown of processes

    • use to manage your gunicorn service: service gunicorn [start | stop | restart]
  7. description "Gunicorn for my Django application" start on runlevel [2345]

    stop on runlevel [!2345] #Send KILL after 5 seconds kill timeout 5 respawn env PROJECT_ROOT="/opt/my_django_app" script exec python $PROJECT_ROOT/portal/manage.py run_gunicorn -- settings=settings.production --preload -w 16 --log-level debug --log- file /var/log/my_django_app/gunicorn.log -p /var/run/gunicorn.pid end script /etc/init/gunicorn.conf