Created
May 2, 2011 19:37
-
-
Save prestontimmons/952217 to your computer and use it in GitHub Desktop.
Sample mod_wsgi Django file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
WSGI application configuration. | |
Read http://code.google.com/p/modwsgi/wiki/IntegrationWithDjango to learn | |
more about integrating with Django. | |
""" | |
import os | |
import site | |
import sys | |
# | |
# Settings configuration | |
# | |
os.environ['DJANGO_SETTINGS_MODULE'] = 'myproject.settings' | |
# | |
# Path information | |
# | |
WSGI_ROOT = os.path.realpath(os.path.dirname(__file__)) | |
SITE_ROOT = os.path.dirname(WSGI_ROOT) | |
PATHS = [ | |
SITE_ROOT, | |
] | |
# | |
# Virtualenv configuration | |
# | |
activate_this = os.path.join(SITE_ROOT, "siteenv/bin/activate_this.py") | |
execfile(activate_this, dict(__file__=activate_this)) | |
# | |
# Path Configuration | |
# Configure the system path for the wsgi process to mirror the virtualenv | |
# http://code.google.com/p/modwsgi/wiki/VirtualEnvironments | |
# | |
# Remember original sys.path. | |
prev_sys_path = list(sys.path) | |
# Add each new site-packages directory. | |
for path in PATHS: | |
site.addsitedir(path) | |
# Reorder sys.path so new directories are at the front. | |
new_sys_path = [] | |
for item in list(sys.path): | |
if item not in prev_sys_path: | |
new_sys_path.append(item) | |
sys.path.remove(item) | |
sys.path[:0] = new_sys_path | |
# | |
# Define the wsgi application | |
# | |
import django.core.handlers.wsgi | |
_application = django.core.handlers.wsgi.WSGIHandler() | |
def application(environ, start_response): | |
""" | |
Custom application to properly forward the url scheme (http/https) | |
to Apache when served behind a proxy by nginx. | |
""" | |
environ['wsgi.url_scheme'] = environ.get('HTTP_X_URL_SCHEME', 'http') | |
return _application(environ, start_response) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment