阿里云ECS部署Flask(Nginx,gunicorn,supervisor,fabric,ubuntu16.04)
来源:互联网 发布:淘宝怎么绑定手机号 编辑:程序博客网 时间:2024/06/05 03:01
先上网站 http://139.224.235.140/,(域名还没弄好)
一、编写fabric脚本
fabric只支持python2,只需要在开发机子上安装python2,服务器不需要
编写fabric脚本,把flask程序打包并上传到阿里云ECS的ubuntu服务器
针对狗书编写的脚本如下:
# -*- coding: utf-8 -*-import os, refrom datetime import datetimefrom fabric.api import *env.user='root'env.password='****'env.hosts=['112.233.244.255']_TAR_FILE='huu-flask.tar.gz'def build(): includes=['app','config.py','manage.py','requirements.txt'] excludes=['__pycache__','*.pyc','*.pyo'] local('rm -f dist/%s'%_TAR_FILE) with lcd(os.path.abspath('.')): cmd=['tar','--dereference','-czvf','./dist/%s'%_TAR_FILE] cmd.extend(includes) cmd.extend(['--exclude=\'%s\''% ex for ex in excludes]) local(' '.join(cmd))_REMOTE_TMP_TAR='/tmp/%s'%_TAR_FILE_REMOTE_BASE_DIR='/srv/flasky'def deploy(): newdir='flasky-%s'%datetime.now().strftime('%y-%m-%d_%H.%M.%S') run('rm -f %s'%_REMOTE_TMP_TAR) put('dist/%s'%_TAR_FILE,_REMOTE_TMP_TAR) with cd(_REMOTE_BASE_DIR): run('mkdir %s'%newdir) with cd('%s/%s'%(_REMOTE_BASE_DIR,newdir)): run('tar -xzvf %s'%_REMOTE_TMP_TAR) with cd(_REMOTE_BASE_DIR): run('rm -rf flasky') run('ln -s %s flasky'%newdir)
二、用supervisor启动flask程序
首先生成配置:
mkdir /etc/supervisorecho_supervisord_conf > /etc/supervisor/supervisord.conf
编写配置:
[program:flasky]command=/srv/venv3/bin/gunicorn manage:app --access-logfile /srv/flasky/flasky/logs/flasky.logdirectory=/srv/flasky/flaskyuser=root#用gunicorn启动flask下面这个配置好像不管用,可以在gunicorn启动命令中加入log日志文件stdout_logfile=/srv/flasky/flasky/logs/flasky.logenvironment=A="1",B="2" #可以设置环境变量,虚拟环境添加PATH=""
启动:
supervisord -c /etc/supervisor/supervisord.confsupervisorctl start flasky
查看状态:
supervisor本身的日志文件在 /tmp/supervisord.log
supervisorctl status
三、配置Nginx
在/etc/nginx/sites-available下有default可以备份后修改
server { listen 80; # 监听80端口 root /srv/flask/www; access_log /srv/flask/log/access_log; #默认在/var/log/nginx error_log /srv/flask/log/error_log;#默认在/var/log/nginx # server_name awesome.liaoxuefeng.com; # 配置域名 # 处理静态文件/favicon.ico: location /favicon.ico { root /srv/flask/www; } # 处理静态资源: location ~ ^\/static\/.*$ { root /srv/flask/www; } # 动态请求转发到9000端口: location / { proxy_pass http://127.0.0.1:9000; proxy_set_header X-Real-IP $remote_addr; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; }
最后, /etc/init.d/nginx reload
就可以查看网站了
阅读全文
0 0
- 阿里云ECS部署Flask(Nginx,gunicorn,supervisor,fabric,ubuntu16.04)
- 阿里云ECS+Gunicorn+Supervisor+Nginx部署Flask
- 阿里云ESC网站部署Flask+gunicorn+nginx+supervisor
- 阿里云ECS上环境搭建(virtualenv+flask+gunicorn+supervisor+nginx)
- 阿里云ubuntu16.04上搭建gunicorn+supervisor+nginx详解
- python web 部署:nginx + gunicorn + supervisor + flask
- 网站部署过程 Nginx + Gunicorn +Supervisor +Flask
- Flask Nginx Gunicorn Supervisor 网站部署 详解
- Flask部署 —— nginx+gunicorn+supervisor
- python web 部署:nginx + gunicorn + supervisor + flask 部署笔记
- python web 部署:nginx + gunicorn + supervisor + flask 部署笔记
- python web 部署:nginx + gunicorn + supervisor + flask 部署笔记
- python web 部署:nginx + gunicorn + supervisor + flask 部署笔记
- python web 部署:nginx + gunicorn + supervisor + flask 部署笔记
- Flask + Gunicorn + Nginx 部署
- Flask + Gunicorn + Nginx 部署
- Flask + Gunicorn + Nginx 部署
- nginx&gunicorn&django阿里云简单部署
- win7 vs2013编译libpng png++ mboben_spixel
- TeamViewer——一款强大的远程控制工具
- [caioj 1086]进攻策略---完全背包+二分查找+单调队列
- 【BS学习】牛腩新闻发布系统——验证码的实现
- 异常
- 阿里云ECS部署Flask(Nginx,gunicorn,supervisor,fabric,ubuntu16.04)
- skynet底层源码阅读(7)-网络服务
- VS2015的相关操作笔记
- JAVA函数和数组
- hdu 6096 ac自动机 和 处理字符串分段输入
- 国庆怎么过
- Average Score
- lg2782 友好城市
- python(四)二分查找法