1. Deploying Snowy with mod_wsgi
1.1. Introduction
If you are running your own server, you may wish to deploy Snowy using Apache and mod_wsgi. This guide is intended to help you do just that. I used the following guides:
http://ericholscher.com/blog/2008/jul/8/setting-django-and-mod_wsgi/
http://docs.djangoproject.com/en/dev/howto/deployment/modwsgi/
Large parts of this guide have been stolen from the Snowy/Install/ModPython, many thanks to SandyArmstrong for writing it.
1.2. Prerequisites
You need to already have apache and mod_wsgi installed and properly configured.
This can be done with the following steps on Ubuntu Server 8.04:
apt-get install libapache2-mod-wsgi a2enmod wsgi
And Fedora/Redhat:
yum install httpd mod_wsgi
I'm also assuming that since you run your own server, you've already tested your Snowy install using the Django test server (manage.py runserver), followed the instructions in INSTALL, etc.
1.3. Setup
In this example, we will run Snowy in http://mydomain.com/. You need to create a new site with the following configuration file:
WSGIPassAuthorization On
WSGIApplicationGroup %{GLOBAL}
Alias /media/ DJANGO_DIR/contrib/admin/media/
WSGIDaemonProcess snowy user=USERNAME home=/path/to/snowy
WSGIProcessGroup snowy
WSGIScriptAlias / /path/to/snowy/snowy.wsgiOn an Ubuntu system, this is done by putting the above in /etc/apache2/sites-available/snowy and running a2ensite snowy afterwards.
Important notes:
Using WSGIPassAuthorization enables the wsgi mod to access the authorization headers of a request. This is disabled by default and leads to problems with the REST api.
Replace USERNAME with your user name (ie. the one you checked the Snowy source with).
Replace DJANGO_DIR with the path django has been installed in. On my system, this was /usr/lib/python2.5/site-packages/django
Now we need to create the snowy.wsgi file mentioned in the WSGIScriptAlias directive. Create it in the snowy directory with the following content:
import os import sys sys.stdout = sys.stderr sys.path.insert(0, '/path/to/snowy') sys.path.insert(1, '/path/to') os.environ['DJANGO_SETTINGS_MODULE'] = 'snowy.settings' import django.core.handlers.wsgi application = django.core.handlers.wsgi.WSGIHandler()
Now restart apache and you're done. Have fun with Snowy!
1.4. Appendix A: Running Snowy as a WSGI process in a SSL Virtual Host
Since I experienced quite few problems while running Snowy inside the docroot of an already existing virtual host, here is the complete definition of a virtual host running snowy, and augmented by SSL (Apache 2.2 needed to use multiple virtual hosts on the same IP address).
<VirtualHost _default_:443>
ServerName domain_name_of_the_virtual_host
LogLevel info
ErrorLog /var/log/apache2/snowy_ssl_error_log
TransferLog /var/log/apache2/snowy_ssl_access_log
SSLEngine on
SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL
SSLCertificateFile /path/to/snowy_crt.pem
SSLCertificateKeyFile /path/to/snowy_key.pem
Alias /media/ /path/to/django_media_file/
WSGIPassAuthorization On
WSGIDaemonProcess snowy_ssl_vh user=USERNAME home=/home/path/to/snowy
WSGIProcessGroup snowy_ssl_vh
WSGIScriptAlias / /path/to/snowy/snowy.wsgi
<Directory "/path/to/snowy/">
Options -Indexes FollowSymLinks
AllowOverride AuthConfig FileInfo
Order allow,deny
Allow from all
</Directory>
# The following directive takes into account whether
# the media directory is outside the docroot
<Directory "/path/to/django_media_file/">
Options -Indexes FollowSymLinks
AllowOverride AuthConfig FileInfo
Order allow,deny
Allow from all
</Directory>
</VirtualHost>Remember to add to the local_settings.py file the following directive:
URI_SCHEME = 'https'