阿里雲下利用寶塔運維配置Django執行環境(多站點)

途徒發表於2019-05-20

前提:在寶塔裡新建站點: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

配置檔案:將此段程式碼放到此站點的配置文件裡
這裡寫圖片描述

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

相關文章