Apache + Django + WSGI 配置

下面假设我的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"

 

  • 在d:/works/web下面使用python django-admin.py startproject myweb来创建应用程序myweb
  • 在django的应用程序目录myweb下创建目录apache,然后在目录下放置如下两个文件apache_django_wsgi.conf和django.wsgi

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的欢迎页面

你可能感兴趣的:(apache,Web,django,python,OS)