当前位置: 移动技术网 > IT编程>网页制作>CSS > Centos部署django教程(代码)

Centos部署django教程(代码)

2017年12月22日  | 移动技术网IT编程  | 我要评论

yum install httpd httpd-devel

yum install mod_wsgi

1、主配置文件是/etc/httpd/conf/httpd.conf

主配置文件加后加:

LoadModule  wsgi_module modules/mod_wsgi.so

2、在项目目录下新建wsgi,里面新建django.wsgi,内容如下

import os
import sys
import django.core.handlers.wsgi
from django.conf import settings
# Add this file path to sys.path in order to import settings
sys.path.insert(0, os.path.join(os.path.dirname(os.path.realpath(__file__)), '..'))
os.environ['DJANGO_SETTINGS_MODULE'] = 'lxyproject.settings'
sys.stdout = sys.stderr
DEBUG = True
application = django.core.handlers.wsgi.WSGIHandler()

必须配置项目路径到系统路径中,因为要通过项目路径找到settings.py配置文件。也就是sys.path.insert(0, os.path.join(os.path.dirname(os.path.realpath(__file__)),'..'))。

DJANGO_SETTINGS_MODULE必须指向项目的settings.py文件。

3、配置django项目虚拟主机

在/etc/httpd/conf.d中添加配置文件lxyproject.conf


WSGIScriptAlias / /srv/lxyproject/wsgi/django.wsgi
Alias /static/ /srv/lxyproject/collectedstatic/
ServerName 10.1.101.31
#ServerName example.com
#ServerAlias www.example.com

    Options Indexes  FollowSymLinks
    AllowOverride None
    Require all granted


    Require all granted

ErrorLog   /etc/httpd/logs/lxyproject.error.log
LogLevel warn

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网