Skip to content

zhuohengfeng/Ryan_Flask_Base

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

我的Flask基础框架

初始化数据库

python manager.py db init
python manager.py db migrate
python manager.py db upgrate


运行服务器(Flask-script的默认命令)

python manager.py runserver


运行shell---查看app, db等

python manager.py shell


部署

一. 虚拟环境virtualenv:

1.sudo pip insatll virtualenv
2.virtualenv venv
3.source venv/bin/activate
4.(venv) pip insatll -r requirements.txt
5.deactivate

二. supervisor

1.sudo apt-get install supervisor
2.vim /etc/supervisor/supervisord.conf
在配置文件中,最后一行加入,表示只要我们的配置文件在以下目录:
[include]
files = /etc/supervisor/conf.d/*.conf
3.sudo vim /etc/supervisor/conf.d/app.conf
[program:fwg]
command=/home/ubuntu/www/fwg/venv/bin/gunicorn manager:app -c /home/ubuntu/www/fwg/gunicorn.conf
directory=/home/ubuntu/www/fwg
autostart=true
autorestart=true
stdout_logfile=/home/ubuntu/www/fwg/logs/gunicorn_supervisor.log

4.进入supervisor的控制台supervisorctl,可以看到app已经running了
sudo supervisorctl app 5.之后可以通过stop app停止app, status来查看。再次启动start app。退出exit 6.supervisor 是服务端,而supervisorctl 是客户端。所以要先确保服务端启动: service supervisor start / stop..... 7.要在工程目录下创建一个log目录给 supervisor存放log用

三.gunicorn

1.安装在venv中,见requirements.txt
2.配置gunicorn文件:/home/ubuntu/www/fwg/gunicorn.conf
工作进程数为3
workers = 3
绑定本地8000端口
bind = '127.0.0.1:8080'

四.nginx的配置

1.启动 sudo service nginx status
2.进入/etc/nginx
注意其中的site-availabe和sites-enable 这2个目录
site-availabe放的是可用的配置文件
sites-enable 放的是生效的配置文件
所以只要在site-availabe创建配置文件,然后再sites-enable 创建软连接即可
3.创建配置文件----- 注意需要修改或者删除默认的default文件
sudo vim sites-available/fwg_site
server {
listen 80;
location /static {
alias /home/ubuntu/www/fwg/static;
}
location / {
proxy_pass http://127.0.0.1:8080;
}
}
4.创建软连接:sudo ln -s ../sites-available/todo_app .
5.重新加载配置,并重启nginx
sudo service nginx reload
6.如果有错误可以查看日志:
access_log /var/log/nginx/access.log
error_log /var/log/nginx/error.log

About

【python】A web site demo based on python flask

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published