在CentOS下部署Apache+Django

部署环境:CentOS6,Apache-httpd-2.4,Python-3.8,Django-3.1

一、编译安装httpd-2.4:

# tar -zxvf httpd-2.4.17.tar.gz
# cd httpd-2.4.17
# ./configure --prefix=/usr/local/apache2.4 --with-included-apr --with-apr=/path/to/apr-httpd --with-apr-util=/path/to/apr-util-httpd/ --with-pcre=/path/to/pcre --with-ssl=/path/to/openssl --enable-so
# make && make install

二、编译安装Python3

# yum install libffi-devel    //避免使用pip时出现ModuleNotFoundError: No module named '_ctypes'错误
# tar -xvJf Python-3.8.5.tar.xz
# cd Python-3.8.5
# ./configure --prefix=/usr/local/python3.8.5 CFLAGS=-fPIC  //CFLAGS=-fPIC可避免后面编译mod_wsgi模块时出错

# vim Modules/Setup     //修改Setup文件,以支持ssl

 

 

 

其中SSL=... 根据你实际情况填写。

# make && make install
# cd /usr/local
# ln -s python-3.8.5/ python3
# vim /etc/profile     //将python3加入PATH路径   export PATH=$PATH:/usr/local/python3/bin

# python3        //检查python安装是否成功

三、编译安装mod_wsgi:

# tar -zxvf mod_wsgi-4.7.1.tar.gz
# cd mod_wsgi-4.7.1
# ./configure --with-apxs=/usr/local/apache/bin/apxs --with-python=/usr/local/python3/bin/python3
# make
# make install

这时可以在apache的modules目录下找到mod_wsgi.so

四、配置apache+django:

假设django项目在/home/django-test/mysite目录下:

编辑httpd.conf文件,增加如下配置:

LoadModule wsgi_module modules/mod_wsgi.so

WSGIScriptAlias / /home/django-test/mysite/mysite/wsgi.py
WSGIPythonHome /home/django-test/venv
WSGIPythonPath /home/django-test/mysite

<Directory /home/django-test/mysite/mysite>
<Files wsgi.py>
Require all granted
</Files>
</Directory>

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值