web.conf

<VirtualHost *:>
WSGIScriptAlias / /var/www/datacn/datacn/wsgi.py
Alias /static/ /var/www/datacn/static/ ServerName 192.168.1.49
#ServerName example.com
#ServerAlias www.example.com <Directory /var/www/datacn/static>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory> <Directory /var/www/datacn/>
Require all granted
</Directory>
ErrorLog /etc/httpd/logs/datacn.error.log
LogLevel warn
</VirtualHost>

升级pip

因为python3.5自带pip,setuptools

/usr/python3./bin/pip3 install --upgrade pip

ln -s /usr/python3./bin/pip3 /usr/bin/pip3

参考:http://www.cnblogs.com/edward2013/p/5289056.html

参考:http://www.cnblogs.com/starof/p/4685132.html

centos下安装pip时失败:

[root@wfm ~]# yum -y install pip
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
* base: mirrors.tuna.tsinghua.edu.cn
* extras: mirrors.tuna.tsinghua.edu.cn
* updates: mirrors.tuna.tsinghua.edu.cn
Setting up Install Process
No package pip available.
Error: Nothing to do

解决方法:

  

需要先安装扩展源EPEL。

EPEL(http://fedoraproject.org/wiki/EPEL) 是由 Fedora 社区打造,为 RHEL 及衍生发行版如 CentOS、Scientific Linux 等提供高质量软件包的项目。

首先安装epel扩展源:

sudo yum -y install epel-release

然后再安装pip

~]# sudo yum -y install python-pip
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
epel/metalink | 4.9 kB 00:00 
* base: mirrors.tuna.tsinghua.edu.cn
* epel: mirrors.neusoft.edu.cn
* extras: mirrors.tuna.tsinghua.edu.cn
* updates: mirrors.tuna.tsinghua.edu.cn
epel | 4.3 kB 00:00 
epel/primary_db | 5.8 MB 00:07 
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package python-pip.noarch 0:7.1.0-1.el6 will be installed
--> Processing Dependency: python-setuptools for package: python-pip-7.1.0-1.el6.noarch
--> Running transaction check
---> Package python-setuptools.noarch 0:0.6.10-3.el6 will be installed
--> Finished Dependency Resolution


Dependencies Resolved


================================================================
Package Arch Version Repository
Size
================================================================
Installing:
python-pip noarch 7.1.0-1.el6 epel 1.5 M
Installing for dependencies:
python-setuptools noarch 0.6.10-3.el6 base 336 k


Transaction Summary
================================================================
Install 2 Package(s)


Total download size: 1.9 M
Installed size: 8.1 M
Downloading Packages:
(1/2): python-pip-7.1.0-1.el6.noarch.rpm | 1.5 MB 00:01 
(2/2): python-setuptools-0.6.10-3.el6.no | 336 kB 00:00 
----------------------------------------------------------------
Total 755 kB/s | 1.9 MB 00:02 
warning: rpmts_HdrFromFdno: Header V3 RSA/SHA256 Signature, key ID 0608b895: NOKEY
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
Importing GPG key 0x0608B895:
Userid : EPEL (6) <epel@fedoraproject.org>
Package: epel-release-6-8.noarch (@extras)
From : /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : python-setuptools-0.6.10-3.el6.noarch 1/2 
Installing : python-pip-7.1.0-1.el6.noarch 2/2 
Verifying : python-pip-7.1.0-1.el6.noarch 1/2 
Verifying : python-setuptools-0.6.10-3.el6.noarch 2/2


Installed:
python-pip.noarch 0:7.1.0-1.el6


Dependency Installed:
python-setuptools.noarch 0:0.6.10-3.el6


Complete!

OK 成功!

pip install --upgrade pip

[root@bogon httpd]# pip install django
Collecting django
Downloading Django-1.11.-py2.py3-none-any.whl (.9MB)
% |████████████████████████████████| .0MB 116kB/s
Collecting pytz (from django)
Downloading pytz-2017.2-py2.py3-none-any.whl (484kB)
% |████████████████████████████████| 491kB 191kB/s
Installing collected packages: pytz, django
Successfully installed django-1.11. pytz-2017.2
You are using pip version 8.1., however version 9.0. is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
[root@bogon httpd]# pip install --upgrade pip
Collecting pip
Downloading pip-9.0.-py2.py3-none-any.whl (.3MB)
% |████████████████████████████████| .3MB 462kB/s
Installing collected packages: pip
Found existing installation: pip 8.1.
Uninstalling pip-8.1.:
Successfully uninstalled pip-8.1.
Successfully installed pip-9.0.

一、安装httpd服务

apache在centos7中是Apache HTTP server。如下对httpd的解释就是Apache HTTP Server。所以想安装apache其实是要安装httpd。

httpd.x86_64 : Apache HTTP Server

安装:

# yum install httpd

设置httpd服务开机启动

[root@yl-web httpd]# /sbin/chkconfig httpd on
Note: Forwarding request to 'systemctl enable httpd.service'.
ln -s '/usr/lib/systemd/system/httpd.service' '/etc/systemd/system/multi-user.target.wants/httpd.service'

启动httpd服务

[root@yl-web httpd]# /sbin/service httpd start
Redirecting to /bin/systemctl start httpd.service

访问ip验证一下,成功!

二、配置

httpd默认的配置文件目录为

[root@yl-web httpd]# cd /etc/httpd/
[root@yl-web httpd]# ls
conf conf.d conf.modules.d logs modules run

主配置文件是/etc/httpd/conf/httpd.conf。

配置存储在的/etc/httpd/conf.d/目录。

1、主配置文件

看一下主配置文件httpd.conf里有用的配置项

#服务器根目录
ServerRoot "/etc/httpd" #端口
#Listen 12.34.56.78:80
Listen 80 #域名+端口来标识服务器,没有域名用ip也可以
#ServerName www.example.com:80 #不许访问根目录
<Directory />
AllowOverride none
Require all denied
</Directory> # 文档目录
DocumentRoot "/var/www/html" # 对 /var/www目录访问限制
<Directory "/var/www">
AllowOverride None
# Allow open access:
Require all granted
</Directory> # 对/var/www/html目录访问限制
<Directory "/var/www/html">
   Options Indexes FollowSymLinks
   AllowOverride None
  Require all granted
</Directory> # 默认编码
AddDefaultCharset UTF-8 #EnableMMAP off
EnableSendfile on
# include进来其它配置文件 IncludeOptional conf.d/*.conf

2、下载配置mod_wsgi

安装mod_wsgi前先进行apache的apxs扩展

http-devel 是为了apxs,yum后你可以whereis apxs去寻找他,然后后边编译使用。

# yum install -y httpd-devel

下载

[root@yl-web collectedstatic]# yum install mod_wsgi

在httpd.conf中增加下面配置:

LoadModule  wsgi_module modules/mod_wsgi.so

该配置用来连接django.wsgi,使工程被apache加载。

配置django wsgi

在项目目录下新建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()

配置wsgi时,

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

修改了wsgi的配置后必须重启httpd服务。

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 <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>

其中

  • WSGIScriptAlias 直接告诉apache,这个虚拟主机中,请求/就交给WSGI处理,也就是项目中配置的django.wsgi会指明。
  • Alias 说明访问/static/直接从DocumentRoot中获取,而无需经过WSGI处理。

现在就可以通过apache服务器配置的IP访问django项目了。

django安装mysqlclient组件遇到的问题:

centos7 解决 Python.h:没有那个文件或目录 错误的方法

sudo yum install python-devel

/usr/python3./bin/pip3 install --upgrade pip

ln -s /usr/python3./bin/pip3 /usr/bin/pip3

/usr/python3./lib/python3./site-packages

ln -s /usr/python3./lib/python3./site-packages/django/bin/django-admin.py    /usr/bin/django-admin.py

ln -s /usr/python3./bin/python3. /usr/bin/python

ln -s /usr/python3./bin/pip3 /usr/bin/pip3

安装mysqlclient报错:

Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-ue65k1mc/mysqlclient/

yum install mysql-devel

CentOS71611部署Django的更多相关文章

  1. mac osx 上面部署Django项目 apache+mysql+mod_wsgi

    1.安装Xcode command line tools 首先,编译mysql和Homebrew需要用到Xcode command line tools,所以首先安装command line tool ...

  2. Ubuntu上通过nginx部署Django笔记

    Django的部署可以有很多方式,采用nginx+uwsgi的方式是其中比较常见的一种方式.今天在Ubuntu上使用Nginx部署Django服务,虽然不是第一次搞这个了,但是发现还是跳进了好多坑,g ...

  3. Apache2.4部署django出现403 Forbidden错误解决办法

    前言:Apache2.4部署django出现403 Forbidden错误最好要结合apache中的错误日志来观察出现何种错误导致出现403错误 下午百度了一下午没找到解决办法,试了n种方法,简直坑爹 ...

  4. 五步教你实现使用Nginx+uWSGI+Django方法部署Django程序

    Django的部署可以有很多方式,采用nginx+uwsgi的方式是其中比较常见的一种方式. 在这种方式中,我们的通常做法是,将nginx作为服务器最前端,它将接收WEB的所有请求,统一管理请求.ng ...

  5. Ubuntu16.04 apache2 wsgi 部署django

    在Ubuntu16.04上部署django其实还算简单直观,最重要的问题就是路径设置正确,并且保证版本统一,这个测试是在 Apache/2.4.18 (Ubuntu)  apt-get install ...

  6. 通过Nginx部署Django(基于ubuntu)

    Django的部署可以有很多方式,采用nginx+uwsgi的方式是其中比较常见的一种方式. 在这种方式中,我们的通常做法是,将nginx作为服务器最前端,它将接收WEB的所有请求,统一管理请求.ng ...

  7. apache部署django记录

    在ubuntu下通过apache部署django 首先需要下载python,django,apache以及wsgi模块 python基本已经自带,我用的是2.7,不是的话可以重新装一个 下载djang ...

  8. Docker 使用指南 (六)—— 使用 Docker 部署 Django 容器栈

    版权声明:本文由田飞雨原创文章,转载请注明出处: 文章原文链接:https://www.qcloud.com/community/article/98 来源:腾云阁 https://www.qclou ...

  9. Windows下Apache部署Django过程记录

    Win7/Apache/Python2.7/Django1.9部署Web   环境: Windows7 Apache httpd-2.4.16-win64-VC14 Python2.7.11 Djan ...

随机推荐

  1. 自己写着玩的一个天气APP

    打开的界面: 向上滑动,进入主界面: 省份界面: 城市界面: 加载天气界面: 显示天气界面: 侧滑,显示地区,然后根据天气来显示一首诗句(晴,多云,雪,雨什么的): 第一次启动App的时候才会加载数据 ...

  2. window 下编译cef 内核 加入mp3/mp4 支持

    下载 depot_tools 解压,加入到环境变量 进入cmd(管理员)运行 gclient 获取 python和git,svn,设置python环境变量 创建新文件夹 mkdir chromium ...

  3. 一只小蜜蜂(斐波那契dp)

    有一只经过训练的蜜蜂只能爬向右侧相邻的蜂房,不能反向爬行.请编程计算蜜蜂从蜂房a爬到蜂房b的可能路线数. 其中,蜂房的结构如下所示. Input输入数据的第一行是一个整数N,表示测试实例的个数,然后是 ...

  4. OK6410&nbsp;tftp下载内核、文件系…

    飞凌官方提供了一键下载烧写linux的方式,相对来说比较方便,但是对于开发来说不够灵活,因此这篇文章把tftp相关的点介绍一下,整理下其中遇到的一些问题. 一键烧写本质上是启动位于SD卡中的Uboot ...

  5. Spring总结十:事务案例

    数据库表Account: 导包: <dependencies> <!--测试--> <dependency> <groupId>junit</gr ...

  6. codeforce453DIV2——D. GCD of Polynomials

    题意 给出n(1–150). 输出两个多项式A,B从常数到最高次的系数,使得对两个多项式求gcd时,恰好经过n步得到结果. 多项式的gcd一步是指(A(x),B(x))变成(B,A mod B)的过程 ...

  7. Angular问题04 模块导入错误???、BrowserModule模块重复加载???、material模块引入后报错

    1 模块导入错误 1.1 问题描述 项目启动时报错:元数据错误,错误截图如下: 1.2 问题原因 利用VsCode开发angular项目时利用自动导入出现错误 坑01:VsCode 的自动导入功能比较 ...

  8. Luogu 4198 楼房重建

    BZOJ 2957 挺妙的题. 先把题目中的要求转化为斜率,一个点$(x, y)$可以看成$\frac{y}{x}$,这样子我们要求的就变成了一个区间内一定包含第一个值的最长上升序列. 然后把这个序列 ...

  9. Smarty3——foreach

    foreach and  foreachelse篇 foreach用于遍历数组,可以是非关联数组,与section相比要简单些,在smarty3中可以接受没有名称的属性,也可以使用smarty2有名称 ...

  10. 跨库连接报错Server 'myLinkedServer' is not configured for RPC

    Solution: Problem is most likely that RPC is not configured for your linked server. That is not a de ...