下面假设我的django应用程序放置在d:/works/web/myweb/
今天参考mod_wsgi的教程,配置了基于apache+mod_wsgi的django的部署,下面记录下来,以备将来参考
#WSGI For Python Integration
LoadModule wsgi_module modules/mod_wsgi.so
再在httpd.conf的最后部分添加Include "d:/works/web/myweb/apache/apache_django_wsgi.conf"
apache_django_wsgi.conf的内容为:
Alias /site_media/ "d:/works/web/myweb/media/"
<Directory "d:/works/web/myweb/media">
Order allow,deny
Options Indexes
Allow from all
IndexOptions FancyIndexing
</Directory>
Alias /media/ "D:/Sources/Library/django/django/contrib/admin/media/"
<Directory "D:/Sources/Library/django/django/contrib/admin/media">
Order allow,deny
Options Indexes
Allow from all
IndexOptions FancyIndexing
</Directory>
WSGIScriptAlias / "d:/works/web/myweb/apache/django.wsgi"
<Directory "d:/works/web/myweb/apache">
Allow from all
</Directory>
django.wsgi的内容为:
import os, sys
#Calculate the path based on the location of the WSGI script.
apache_configuration= os.path.dirname(__file__)
project = os.path.dirname(apache_configuration)
workspace = os.path.dirname(project)
sys.path.append(workspace)
os.environ['DJANGO_SETTINGS_MODULE'] = 'myweb.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
print >> sys.stderr, sys.path
然后启动apache的web服务器,输入http://localhost就会出现Django的欢迎页面