|
/Admin/Apache:
Django on Apache Using mod_wsgi on CentOS 5
These [1][2] would indicate mod_wsgi is the best way to server Django sites using Apache.
mod_wsgi does not seem to exist in the CentOS 5 repositories. Using this[3] as my guide, I installed from source as follows:
cd /usr/lib/python2.4/config ln -s ../../../lib64/libpython2.4.so . cd wget http://modwsgi.googlecode.com/files/mod_wsgi-3.3.tar.gz tar -xf mod_wsgi-3.3.tar.gz cd mod_wsgi-3.3 yum install httpd-devel ./configure --with-python=/usr/bin/python2.4 make make install
That all seemed to go well, and now I see this file: /usr/lib64/httpd/modules/mod_wsgi.so
Turn this module on in Apache, by adding the following lines to /etc/httpd/conf/httpd.conf:
LoadModule wsgi_module /usr/lib64/httpd/modules/mod_wsgi.so
AddHandler wsgi-script .wsgi
After "/etc/init.d/httpd restart" apache is still working. A very good sign.....
It is worth noting that the reference[3] I am using for this also installed Python2.5 from source at the start of the whole process. CentOS 5 only has Python2.4. The reference did not justify why this was done, lets just cross our fingers and hope it will not be necessary.
Now lets see if we can get Apache to server up my helloWorld Django site. This[4] seems to be the most authoritative document I can find on the subject.
cd /var/www/html/django/chinawandererCreate file /var/www/html/django/chinawanderer/apache/django.wsgi which contains the following:
mkdir apache
import os, sys
sys.path.append('/var/www/html/django')
sys.path.append('/var/www/html/django/chinawanderer')
os.environ['DJANGO_SETTINGS_MODULE'] = 'chinawanderer.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
Add this to /etc/httpd/conf/httpd.conf:
And it works. Django in action: http://domain.com/django/chinawanderer/WSGIScriptAlias / /var/www/html/django/chinawanderer/apache/django.wsgi Order deny,allow Allow from all
[1] http://docs.djangoproject.com/en/dev/howto/deployment/
[2] http://docs.djangoproject.com/en/dev/howto/deployment/modwsgi/
[3] http://taoyh163.blog.163.com/blog/static/19580356200971104043225/
[4] https://code.google.com/p/modwsgi/wiki/IntegrationWithDjango
posted at: 08:46 | path: /Admin/Apache | permanent link to this entry