安装Miniconda环境
wget -c https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh
chmod 777 Miniconda3-latest-Linux-x86_64.sh
bash Miniconda3-latest-Linux-x86_64.sh
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
添加Flask项目运行环境
conda create -n flask-movie python=3.6
conda env list
conda activate flask-movie
cd /usr/local/
wget http://files.wanlf.vip/usr/local/flask/flask-movie/flask-movie.tar.gz
tar xf flask-movie.tar.gz && rm -rf flask-movie.tar.gz
cd flask-movie && pip install -r requirments.txt
//进入自己服务器的Mysql数据库
//Mysql 安装可查看 https://wanlingfeng.tech/archives/ubuntu1804mysql56%E5%AE%89%E8%A3%85
mysql -u root -p
CREATE DATABASE movie_cat DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
use movie_cat;
source /usr/local/flask-movie/movie_cat.sql
exit;
修改数据库和端口配置
vim config/base_setting.py
SQLALCHEMY_DATABASE_URI="mysql+pymysql://root:yourpassword@127.0.0.1:3306/movie_cat"
DOMAIN = {
"www":"http://8.134.168.87:5000" //你的ip
}
vim manage.py
manager.add_command( "runserver",Server( host = "0.0.0.0",use_debugger=True,use_reloader= True ) )
启动项目并配置域名
python manager.py runserver //查看运行效果
cd /etc/nginx/conf.d && vim flask_movie.conf
server {
listen 80;
listen [::]:80;
server_name flask-movie.wanlf.vip;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
proxy_pass http://8.134.168.87:5000;
}
}
//修改好后开始重启nginx
nginx -t
nginx -s reload
//nohup python manager.py runserver > nohup.out 2>&1 &
//把manager.py中app.run( host = "0.0.0.0",debug=True )注释取消
//安装后端服务器
pip install gunicorn
//后台启动
nohup gunicorn -w 2 -b 0.0.0.0:5000 manager:app > nohup.out 2>&1 &
//如果宕机可杀进程重启
kill -9 `lsof -Pti:5000`
项目链接
http://flask-movie.wanlf.vip