django apache 經過wsgi部署

生產上部署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

相關文章
相關標籤/搜索