django1.9.1+apache24+mod_wsgi详解(centos)

来源:互联网 发布:网络远程控制门禁系统 编辑:程序博客网 时间:2024/05/16 00:31

这里讲一下centos6或者7下的django搭建,7简单很多,6的话麻烦一点

建议用centos7,因为它自带python2.7,而django后期版本对python2.6不支持

contos7下的环境安装配置:

yum install apr
yum install apr-devel
yum install apr-util
yum install httpd
yum install httpd-devel
yum install mod_wsgi
change httpd.conf
#ServerName localhost:80
配置: mod_wsgi.conf
find / -name "*wsgi.conf"
得到wsgi的配置文件 /etc/httpd/conf.modules.d/10-wsgi.conf
做如下添加:
WSGIScriptAlias / /search/lizhigang/mysite/mysite/wsgi.py
WSGIPythonPath /search/lizhigang/mysite

<Directory /search/lizhigang/mysite/mysite>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
这里需要说明一下,我的Django工程位于“/search/lizhigang/mysite/”

然后访问localhost显示403,关掉selinux setenforce 0
外网访问:
配置iptables:
添加80端口
配置完成

关于django的文件的配置可以参考:

http://blog.csdn.net/shouwangzhelv/article/details/49969217

配置Apache即编辑Apache安装目录conf文件夹下的httpd.conf文件,在文件最后添加如下内容:

LoadModule wsgi_module modules/mod_wsgi.so


WSGIScriptAlias / home/web/web/wsgi.py

WSGIPythonPath /home/web/web

<Directory /home/web/web>
<Files wsgi.py>
    Require all granted
</Files>
</Directory>

Alias /static home/web/trans/static   
<Directory home/web/trans/static>   
    AllowOverride None  
    Options None  
    Require all granted  
</Directory>


centos6下自编译环境配置:

1、首先编译安装python2.7:

参考:http://blog.csdn.net/jcjc918/article/details/11022345

2、编译安装apache和mod_wsgi

首先去官网下载apr-1.5.1.tar.gz,apr-util-1.5.4.tar.gz,pcre-8.36.tar.gz,httpd-2.4.10.tar.gz

说明一下:1、要是本来已经安装了pcre,没有必要重新安装,安装需要gcc,请提前确保已经安装了gcc

 2、如果安装过程出现无法识别指令--with-python=/usr/local/bin/python2.7的警告,没有关系忽略就好。

3、本文编译过程参考了:http://www.centoscn.com/apache/2015/0126/4560.html

1、安装apr

  1. tar -zxvf apr-1.5.1.tar.gz   
  2. cd apr-1.5.1  
  3. ./configure --prefix=/usr/local/apr --with-python=/usr/local/bin/python2.7
  4. make  
  5. make install
2.安装apr-util-1.5.4.tar.gz
 
  1. tar -zxvf apr-util-1.5.4.tar.gz   
  2. cd apr-util-1.5.4  
  3. ./configure --with-apr=/usr/local/apr --with-python=/usr/local/bin/python2.7
  4. make  
  5. make install
3.安装pcre-8.36.tar.gz
 
  1. tar -zxvf pcre-8.36.tar.gz  
  2. cd pcre-8.36  
  3. ./configure --prefix=/usr/local/pcre --with-python=/usr/local/bin/python2.7
  4. make  
  5. make install
4.安装httpd-2.4.10.tar.gz
[plain] view plaincopy
 
  1. tar -zxvf httpd-2.4.10.tar.gz   
  2. cd httpd-2.4.10  
  3. ./configure --prefix=/usr/local/apache --with-apr=/usr/local/apr/ --with-pcre=/usr/local/pcre/  --with-python=/usr/local/bin/python2.7
  4. make  
  5. make install 

5.修改/usr/local/apache/conf/httpd.conf 
找到#ServerName www.example.com:80修改为ServerName localhost:80
6.将http加入service
cp /usr/local/apache/bin/apachectl /etc/rc.d/init.d/httpd  
7.修改/etc/rc.d/init.d/httpd
在#!/bin/bash下加入
[plain] view plaincopy  
# chkconfig: 2345 50 90  
# description:Activates/Deactivates Apache Web Server)  
8.启动apache
[html] view plaincopy  
service httpd start  
9.验证apache是否启动成功
[plain] view plaincopy  
lsof -i:80  
 
出现如下输出则证明apache启动
COMMAND  PID   USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
httpd   4158   root    4u  IPv6  50349      0t0  TCP *:http (LISTEN)
httpd   4159 daemon    4u  IPv6  50349      0t0  TCP *:http (LISTEN)
httpd   4160 daemon    4u  IPv6  50349      0t0  TCP *:http (LISTEN)
httpd   4161 daemon    4u  IPv6  50349      0t0  TCP *:http (LISTEN)
8、安装mod_wsgi

9.如上centos7进行配置




0 0
原创粉丝点击