码迷,mamicode.com
首页 > 其他好文 > 详细

apache2.4配置Django1.7运行环境

时间:2014-09-23 17:14:34      阅读:230      评论:0      收藏:0      [点我收藏+]

标签:blog   http   io   os   ar   文件   div   2014   sp   

系统环境Centos 6.5
这篇文章不适用6以下的系统,因为会碰到这个错误
[Mon Sep 22 18:13:02 2014] [error] [client 10.209.75.90] Truncated or oversized response headers received from daemon process ‘cms‘: /var/www/openapi_cms/openapi_cms/wsgi.py, referer: http://10.210.214.237/api-auth/login/?next=/
[Mon Sep 22 18:13:03 2014] [notice] child pid 6107 exit signal Segmentation fault (11)
[Mon Sep 22 18:27:49 2014] [notice] caught SIGTERM, shutting down

  

基础模块yum安装好
yum -y install gcc pcre-devel zlib-devel openssl-devel bzip2-devel curl-devel openldap-devel
咱们一共需要这几个文件
.
├── get-pip.py
├── httpd-2.4.10.tar.bz2
├── Python-2.7.8.tgz
└── wsgi_4.3.0.tar.gz
安装apache
解压httpd,把下面这两个软件解压到httpd/srclib下并重命名
.
├── apr
├── apr-util
├── Makefile
└── Makefile.in
wget http://mirror.bit.edu.cn/apache/apr/apr-1.5.1.tar.bz2
编译并安装httpd
./configure --prefix=/usr/local/apache --with-included-apr && make && sudo make install
 
重新编译python,不然编译mod_wsgi会报错
wget https://www.python.org/ftp/python/2.7.8/Python-2.7.8.tgz
./configure --prefix=/usr/local/python --enable-shared
 
安装mod_wsgi
./configure --with-apxs=/usr/local/apache/bin/apxs --with-python=/usr/local/python/bin/python
 
配置apache
在配置文件/usr/local/apache/conf/httpd.conf 中增加一行
Include conf/extra/python.conf
编译python.conf
LoadModule wsgi_module modules/mod_wsgi.so
WSGISocketPrefix /var/run/wsgi

<VirtualHost *:80>

ServerName cms.openapi.com

Alias /static/ /usr/local/apache/htdocs/static/

<Directory /usr/local/apache/htdocs/static>
Require all granted
</Directory>

WSGIDaemonProcess daemon python-path=/usr/local/apache/htdocs/openapi_cms:/usr/local/python/lib/python2.7/site-packages
WSGIProcessGroup daemon
WSGIScriptAlias / /usr/local/apache/htdocs/openapi_cms/openapi_cms/wsgi.py

<Directory /usr/local/apache/htdocs/openapi_cms/openapi_cms>
<Files wsgi.py>
Require all granted
</Files>
</Directory>

</VirtualHost>
 
django配置文件settings.py增加静态文件配置
STATIC_URL = ‘/static/‘
STATIC_ROOT = ‘/usr/local/apache/htdocs/static/‘
 
备注:
django默认的模板加载器不包含egg文件的加载器
所以python的所有模块最好都用pip安装 免得给自己找麻烦
pip的安装地址:wget --no-check-certificate https://bootstrap.pypa.io/get-pip.py
/usr/local/python/bin/python get-pip.py
 
get-pip.py需要python的zlib, openssl

apache2.4配置Django1.7运行环境

标签:blog   http   io   os   ar   文件   div   2014   sp   

原文地址:http://www.cnblogs.com/txwsqk/p/3988359.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!