Django2.0+Apache2+mod_WSGI部署在ubuntu16.04
-
安装apache2 (2.4版本)
apt-get install apache2 -
安装mod_wsgi (python3版本)
apt-get install libapache2-mod-wsgi-py3 -
更改/usr/lib/apache2/modules/mod_wsgi.so 到最新版
-
安装依赖
apt-get install apache2-dev apt-get install python3-dev -
源码安装
-
网站 https://github.com/GrahamDumpleton/mod_wsgi/releases
-
如下图右键复制链接到linux中 wget 链接地址

-
解压文件 tar -zvxf 下载的文件
-
cd 进入到解压的文件夹
-
查看apxs和python所在路劲 whereis apxs whereis python
whereis apxs whereis python -
配置
./configure --with-apxs=apxs所在路径 --with-python=python路径 -
编译 安装
make make install
-
-
配置apache2
-
创建自己网站的配置文件,名字随意,必须以.conf结尾
cd /etc/apache2/sites-available mkdir mysite.conf -
配置settings.py

-
编辑配置文件
vim mysite.conf<VirtualHost *:80> WSGIDaemonProcess 项目文件夹名称 python-home=虚拟环境绝对路劲 python-path=项目文件所在得绝对路径 WSGIProcessGroup 项目文件夹名称 WSGIScriptAlias / 项目文件中wsgi.py所在的绝对路径/wsgi.py <Directory 项目文件中wsgi.py所在的绝对路径> <Files wsgi.py> Require all granted </Files> </Directory> # 设置开放静态目录 Alias /static/ 静态文件的STATIC_ROOT绝对路径+/ <Directory > Require all granted </Directory> # 开放上传文件夹 Alias /media/ 上传文件所在的绝对路径+/ <Directory 上传文件所在的绝对路劲> Require all granted </Directory> </VirtualHost> -
重启apache2服务器
apache2ctl restart -
回收静态文件
-
进入到虚拟环境,运行以下命令
python manage.py collectstatic
-
-
-

本文详细介绍如何在Ubuntu16.04上使用Django2.0与Apache2结合mod_WSGI进行网站部署,包括软件安装、配置及重启等步骤。

602

被折叠的 条评论
为什么被折叠?



