Django, Apache 2.2, mod_ssl, and mod_wsgi (Part 2)
Part 1 | Part 2 | Part 3
DNS
I'm going to make an assumption. You have 1 domain and can create hosts under that domain. Fr example, say you own example.com. I'm assuming you have the ability to create "media.example.com" with whomever hosts your DNS.
You'll want to setup 2 domains:
www.example.com
media.example.com
Since this process is virtually different for everyone I won't cover it. Contact your DNS provider for assistance here.
Setting up Apache
If you've never used Apache, you can pretty much control the entire webserver from 1 file: httpd.conf. By default it's located in {apache install direcotory}\conf\httpd.conf. I like to edit it in Wordpad becuase I'm a lightweight, but you're welcome to edit it in whatever hacker-rific editor you prefer.
Installing mod_wsgi
mod_wsgi is a module addon for Apache which is responsible for accepting the incoming HTTP connection, turning that connection into a python object, and then passing it to Django. In other words, it's really important.
- Copy the .so file you downloaded into {apache install directory}\modules.
- Open the httpd.conf file and find the section that has all the "LoadModule"s in it
- Add this line:
LoadModule wsgi_module modules/mod_wsgi.so - This will load the wgi module whenever Apache runs
Let's recall what our objectives for this project are:
- Serve up Django with mod_wsgi by default from the site root
- Serve up static media (images, css, js, etc.) from a separate virtual host
- Offer the Django app in both HTTP and HTTPS
- to hold the Django application
- to hold all of our static media
In case you're wondering, there are a few reasons why this is an ideal setup:
- We want our Django application to worry about 1 thing: serving up python
- It would probably be a performance hit if python had to process all of our media files. It makes more sense to have them directly served by apache
- We can enable caching for everything on our static media virtual host, also improving performance
- It's uber leet cool (no, not really)
NameVirtualHost *:80
<VirtualHost *:80>
ServerName www.example.com:80
ServerAdmin you@example.com
</virtualhost>
<VirtualHost *:80>
ServerName media.example.com:80
ServerAdmin you@example.com
</VirtualHost>
This will give us 2 domains to serve from.
Still to come....
- Configuring wsgi and django
- Configuring django settings to use our virtual hosts
- Adding https support
- Forcing /admin to use https only
0 comments:
Post a Comment