您的位置:首页 > 运维架构 > Apache

CentOS 7 下Apache部署python Django CMS运行环境

2018-03-09 15:19 661 查看
其实django官方文档写的非常详细了。 https://docs.djangoproject.com/en/1.11/ 下面记录下自己遇到的一些问题
yum install mod_wsgi.x86_64

pip install mezzanine
mezzanine-project mlsj
cd mlsj
python manage.py createdb

python manage.py collectstaticpython manage.py collecttemplates
#python manage.py runserver

vi /etc/hosts

127.0.0.1  mlsj.com www.mlsj.com

vi ./mlsj/setting.py

allowhost = ['*']

===========apache配置,注意 为每个网站设置 python= SetEnv,改为统一在网站wsgi文件中修改。 =====
<VirtualHost *:80>

    Servername www.tarzan.com
    DocumentRoot "/tarzan/www/mzproject/mzproject"
    WSGIScriptAlias / "/tarzan/www/mzproject/mzproject/wsgi.py"
  #  SetEnv DJANGO_SETTINGS_MODULE mzproject.settings

    <Directory "/tarzan/www/mzproject/mzproject">
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

<VirtualHost *:80>

    Servername www.mlsj.com
    DocumentRoot "/tarzan/www/mlsj/mlsj"
    WSGIScriptAlias / "/tarzan/www/mlsj/mlsj/wsgi.py"

#SetEnv DJANGO_SETTINGS_MODULE mlsj.settings

    <Directory "/tarzan/www/mlsj/mlsj">
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

======================================

vi ./mlsj/wsgi.py
添加下面两行

import sys
sys.path.append("/tarzan/www/mlsj")

删除默认环境设置并新添加一个。避免多个网站产生冲突
#os.environ.setdefault("DJANGO_SETTINGS_MODULE",
#                      "%s.settings" % real_project_name("mlsj"))
os.environ["DJANGO_SETTINGS_MODULE"] = "mlsj.settings"
 

service httprd start
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: