CentOS服务器配置apache+django

1.安装apache

  1. 安装apache
yum -y install httpd*
  1. 查看安装
rpm -qa | grep httpd

2.安装Django:

  1. 安装pip
wget https://bootstrap.pypa.io/get-pip.py
python get-pip.py
  1. 安装Django:
pip install Django==1.8

3.安装wsgi

  1. 安装http-devel:
yum install -y httpd-devel
  1. 安装mod_wsgi:
yum install mod_wsgi
  1. http.conf 加入:

LoadModule wsgi_module modules/mod_wsgi.so

4.安装MySQLdb

下载地址:https://pypi.python.org/pypi/MySQL-python/1.2.5并上传到/usr/local/src/下

unzip MySQL-python-1.2.5.zip
cd MySQL-python-1.2.5
python setup.py install

5.在django目录下新建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'] = 'pysite.settings'

sys.stdout = sys.stderr

DEBUG = True

application = django.core.handlers.wsgi.WSGIHandler()

6.配置django虚拟主机:

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

<VirtualHost *:100>

WSGIScriptAlias / /var/www/html/pysite/wsgi/django.wsgi
Alias /static/ /var/www/html/pysite/collectedstatic/

ServerName localhost:100
#ServerName example.com
#ServerAlias www.example.com

<Directory /var/www/html/pysite/collectedstatic>
    Options Indexes  FollowSymLinks
    AllowOverride None
    Require all granted
</Directory>

<Directory /var/www/html/pysite/wsgi/>
    Require all granted
</Directory>
ErrorLog   /etc/httpd/logs/pysite.error.log
LogLevel warn
</VirtualHost>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值