Flask- 部署

1.创建虚拟环境文件夹

mkdir src

2.创建虚拟环境
virtualenv --no-site-packages -p /usr/local/bin/python3

3.通过requirement.txt安装Python包
/home/env/houseenv/bin/pip3 install -r /home/src/house/house/requirement.txt

测试环境启动项目
/home/env/houseenv/bin/python3 /home/src/house/house/manage.py runserver -h 0.0.0.0 -p 80 -d
可以把命令放在一个shell文件夹下 start_house.sh
然后给启动权限 chmod -R 777 start_house.sh
使用命令 nohup ./start_house.sh 启动项目

然后会创建一个nohup.out文件
这里面会记录日志
查看日志
tail -f xxx 查看某个文件 并且文件内容有更新时,立马更新
tail -n 10 xxx 查看某个文件最后10行

正式环境
创建houseuwsgi.ini 和housenginx.conf

housenginx.conf内容如下:

server {
listen 80;
server_name 47.107.191.176 localhost;

access_log /home/logs/ajaccess.log;
error_log /home/logs/error.log;

location / {
include uwsgi_params;
    uwsgi_pass 127.0.0.1:8891;

uwsgi_param UWSGI_CHDIR /home/src/house;
uwsgi_param UWSGI_SCRIPT manage:app;
}    

}

houseuwsgi.ini内容如下:

[uwsgi]
master = true
socket = 127.0.0.1:8891
chdir = /home/src/house/house
pythonpath = /home/env/houseenv/bin/python3
callable = app
logto = /home/logs/houseuwsgi.log

home/env/houseenv/bin/uwsgi --ini /home/conf/houseuwsgi.ini启动项目

你可能感兴趣的:(Flask- 部署)