环境
- OS:CentOS 6.2 x64
- Apache:2
- Python:2.6
- Django:1.4.2
场景
我的应用名称是beaver,放在下面的位置:
/var/www/cgi-bin/beaver
需求
使用wsgi,把Django项目,发布到apache下。
第一步:建立beaver.wsgi
在上面的目录中新建一个文件:beaver.wsgi
vi /var/www/cgi-bin/beaver/django.wsgi
输入如下内容:
1 2 3 4 5 6 7 8 9 10
| import os import sys
sys.path.append('/var/www/cgi-bin/beaver') os.environ['DJANGO_SETTINGS_MODULE'] = 'beaver.settings'
os.environ['PYTHON_EGG_CACHE'] = '/var/www/cgi-bin/beaver/.python-egg'
import django.core.handlers.wsgi application = django.core.handlers.wsgi.WSGIHandler()
|
##第二步:为Apache建立配置文件 apache_django_wsgi.conf
该文件存在在下面的位置:
/etc/httpd/conf.d/
输入下面的内容:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| vi /etc/httpd/conf.d/apache_django_wsgi.conf
WSGIScriptAlias /test /var/www/cgi-bin/hello.py
AddHandler wsgi-script .wsgi WSGIScriptAlias / "/var/www/cgi-bin/beaver/django.wsgi"
<Directory "/var/www/cgi-bin/beaver"> Order deny,allow Allow from all Options FollowSymLinks </Directory>
Alias /static "/usr/lib/python2.6/site-packages/django/contrib/admin/static" <Directory "/usr/lib/python2.6/site-packages/django/contrib/admin/static"> Order deny,allow Allow from all IndexOptions FancyIndexing Options FollowSymLinks Indexes MultiViews AllowOverride None </Directory>
|
#第三步: 修改应用目录的属性,使Apache能有权访问应用目录:
1
| chown apache:apache -R /var/www/cgi-bin/beaver/
|
#第四步:启动apache
service httpd start
#第五步:输入http://localhost进行验证