生产上部署django

1. 修改settings关闭debug

DEBUG = False
ALLOWED_HOSTS = ['*']

2. 安装wsgi

yum -y install mod_wsgi      # yum安装因为我的apche是yum安装的 官方下载地址:http://code.google.com/p/modwsgi/

安装完查看apache目录中有没有mod_wsgi.so模块和生成的wsgi.conf的配置文件,wsgi.conf中只是导入了wsgi的模块,如果没有可以手动导入

LoadModule wsgi_module modules/mod_wsgi.so

3. 配置apache的vhost

<VirtualHost *:>
ServerName jumpserver.yolu.com
Alias /static/ /opt/jumpserver/webroot/AutoSa/static
DocumentRoot /opt/jumpserver/webroot/AutoSa # 项目地址
ErrorLog logs/jumpserver.yolu.com-error.log
CustomLog logs/jumpserver.yolu.com-access.log common
WSGIScriptAlias / /opt/jumpserver/webroot/AutoSa/AutoSa/wsgi.py # 项目中django自己生成的wsgi配置文件
<Directory />
Order deny,allow
Allow from all
</Directory>
</VirtualHost>

4. 修改wsgi.py配置文件

import os
import sys
sys.path.append('/opt/jumpserver/webroot/AutoSa') ##加入这行,否则会报导入settings错误的
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "AutoSa.settings") from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

5. 启动httpd测试即可

参考:http://mozillazg.com/2013/01/django-deploying-with-apache-mode-wsgi.html

  

05-08 14:50