Gunicorn, Django & WSGI
Gunicorn, Django & WSGI
& WSGI
Benoît Chesneau
23/05/2010 - djangocon berlin
Tuesday, May 25, 2010
benoît chesneau
Gunicorn author
[email protected]
Minimal web & Opensource
Web craftman
http://www.e-engura.com &
http://benoitc.im
WSGI
Python app
WSGI
Application Python
class CustomHeader(object):
application = CustomHeader(app)
import os
from twod.wsgi import DjangoApplication
os.environ['DJANGO_SETTINGS_MODULE'] = "yourpackage.settings"
django_app = DjangoApplication()
• uWSGI (NGINX)
• mod_wsgi (Apache)
• Unicorn is awesome
• need something stable
• need something simple
• Simple
• Minimal
• Performant
• Unix
def when_ready(server):
....
• gunicorn_django -w 3 -d -p /path/to/
pidfile /myproject/settings.py
• ./manage.py run_gunicorn -w 3
• gunicorn_django -w 3 -k
“egg:gunicorn#eventlet” /myproject/
settings.py
• proxy
• buffering
• secure your app against DOS
proxy_redirect off;
if (!-f $request_filename) {
proxy_pass http://app_server;
break;
}
server {
listen 80 default;
client_max_body_size 4G;
server_name _;
keepalive_timeout 5;
root /path/to/app/current/public;
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
if (!-f $request_filename) {
proxy_pass http://app_server;
break;
}
}
}
proxy_buffering off;
• http://gunicorn.org
• http://e-engura.org
• http://www.python.org/dev/peps/pep-0333/
• http://bitbucket.org/2degrees/twod.wsgi/
• http://github.com/alex/django-wsgi