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


    系统环境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
    make
    make install
     
     添加python lib库配置/etc/ld.so.conf
    /usr/local/python/lib
    
    执行ldconf
     
    安装mod_wsgi
    ./configure --with-apxs=/usr/local/apache/bin/apxs --with-python=/usr/local/python/bin/python
    make
    make install
     
    配置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
    WSGIPassAuthorization On #如果不加这句话 当你用django rest framework写rest api时,用户验证会弹出用户名和密码并显示401错误

    <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
  • 相关阅读:
    Java基础08 继承
    Java基础07 包
    Java基础06 组合
    Java基础05 实施接口
    Java基础04 封装与接口
    Java基础03 构造器与方法重载
    Java基础02 方法与数据成员
    Java基础01 从HelloWorld到面向对象
    151. Reverse Words in a String
    168. Excel Sheet Column Title
  • 原文地址:https://www.cnblogs.com/txwsqk/p/3988359.html
Copyright © 2020-2023  润新知