阿里云下利用宝塔运维配置Django运行环境(多站点)

前提:在宝塔里新建站点:abc.com,安装好nginx、mysql等

一、配置python 3.6 及 pip 3

yum update
yum -y install wget gcc make zlib-devel readline-devel
wget https://www.python.org/ftp/python/3.6.4/Python-3.6.4.tar.xz
xz -d Python-3.6.4.tar.xz
tar -xvf Python-3.6.4.tar
cd Python-3.6.4
./configure --prefix=/usr/local/python3.6 --enable-optimizations # 安装路径
make
make install
ln -s /usr/local/python3.6/bin/python3 /usr/bin/python3
ln -s /usr/local/python3.6/bin/pip3 /usr/bin/pip3

二、安装Django,及上传项目
pip3 install -i https://pypi.douban.com/simple/ django==1.9.8
将调试好的项目上传到宝塔里新建的站点目录下

三、安装uWSGI
pip3 install uwsgi
ln -s /usr/local/python3/bin/uwsgi /usr/bin/uwsgi3
设置uWSGI配置文件:uwsgi.ini

[uwsgi]
socket = 127.0.0.1:9090 #此处一定要和宝塔里的站点配置文件一致
chdir=/www/wwwroot/api.small3d.com #站点目录
module=smallBack.wsgi # 相对于项目根目录的 wsgi位置,smallBack是django默认app
master = true
processes=2
threads=2
max-requests=2000
chmod-socket=664
vacuum=true
daemonize = /www/wwwroot/api.small3d.com/uwsgi.log

启动uwsgi
uwsgi3 -i uwsgi.ini

四、配置nginx

配置文件:将此段代码放到此站点的配置文档里
阿里云下利用宝塔运维配置Django运行环境(多站点)_第1张图片

location /static {
alias /www/wwwroot/abc.com/static;
}
location / {
include /etc/nginx/uwsgi_params;
uwsgi_pass 127.0.0.1:9090;
}
访问abc.com

你可能感兴趣的:(django框架)