Apache+mod_wsgi部署Django

1、安装apache和mod_wsgi,请参考http://my.oschina.net/shniu/blog/206367 

2、配置

    a、上传项目

    b、解压到apache的DocumentRoot所指定的目录,假定为:/usr/local/apache2/htdocs

    cd 到项目目录

    首先修改settings配置,请参考http://my.oschina.net/shniu/blog/206389 

    其次,在包含有manage.py的文件夹里运行

python manage.py syncdb # 创建数据表
pyhton manage.py collectstatic   # 搜集静态文件

    c、修改wsgi.py

import os,sys

sys.path.append(os.path.dirname(os.path.dirname(__file__)))

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "digcredit.settings")
os.environ['PYTHON_EGG_CACHE'] = '/tmp/.python-eggs'

from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

    d、修改httpd.conf

# Virtual hosts
Include /etc/httpd/extra/httpd-vhosts.conf   # 打开注释

   e、修改extra/httpd-vhosts.conf

<VirtualHost *:80>
    ServerName example.com
    ServerAdmin [email protected]

    DocumentRoot "/usr/local/apache2/htdocs/doit"
    WSGIScriptAlias / "/usr/local/apache2/htdocs/doit/doit/wsgi.py"
    
    <Directory "/usr/local/apache2/htdocs/doit">
        Order allow,deny
        Allow from all
    </Directory>

    Alias /media "/usr/local/apache2/htdocs/doit/doit/media"
    Alias /static "/usr/local/apache2/htdocs/doit/doit/collectedstatic"

    <Directory "/usr/local/apache2/htdocs/doit/doit/collectedstatic">
        Order deny,allow
        Allow from all
    </Directory>

    <Directory "/usr/local/apache2/htdocs/doit/doit/media">
        Order deny,allow
        Allow from all
    </Directory>
</VirtualHost>


你可能感兴趣的:(Apache+mod_wsgi部署Django)