生产上部署djangohtml
1. 修改settings关闭debugweb
DEBUG = False ALLOWED_HOSTS = ['*']
2. 安装wsgiapache
yum -y install mod_wsgi # yum安装由于个人apche是yum安装的 官方下载地址:http://code.google.com/p/modwsgi/
安装完查看apache目录中有没有mod_wsgi.so模块和生成的wsgi.conf的配置文件,wsgi.conf中只是导入了wsgi的模块,若是没有能够手动导入django
LoadModule wsgi_module modules/mod_wsgi.so
3. 配置apache的vhostapp
<VirtualHost *:80> 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测试便可google
参考:http://mozillazg.com/2013/01/django-deploying-with-apache-mode-wsgi.htmlspa