Centos 部署django概要

51 篇文章 0 订阅

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

<VirtualHost *:80>
WSGIScriptAlias / /srv/lxyproject/wsgi/django.wsgi
Alias /static/ /srv/lxyproject/collectedstatic/
ServerName 10.1.101.31
#ServerName example.com
#ServerAlias www.example.com
#如若使用virtualenv部署
#WSGIDaemonProcess http://127.0.0.1:80 python-path=/home/user/my_blog_2:/home/user/venv/lib/python3.4/site-packages
#WSGIProcessGroup http://127.0.0.1:80
#WSGIScriptAlias / /home/user/my_blog_2/my_blog_2/wsgi.py
<Directory /srv/lxyproject/collectedstatic>
    Options Indexes  FollowSymLinks
    AllowOverride None
    Require all granted
</Directory>
<Directory /srv/lxyproject/wsgi/>
    Require all granted
</Directory>
ErrorLog   /etc/httpd/logs/lxyproject.error.log
LogLevel warn
</VirtualHost>

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值