把flask部署到服务器

1.新建一个wsgi.py文件

# -*- coding:utf-8 -*-
import sys
from os.path import abspath
from os.path import dirname

sys.path.insert(0, abspath(dirname(__file__)))

import app

# 必须有一个叫做application的变量
# gunicorn 就要这个变量
# 这个变量的值必须是Flask的实力
application = app.app

# 这是把代码部署到 apache gunicorn nginx 后面的套路

2.apt-get install gunicorn  安装gunicorn

3. 在根目录下安装supervisor

4.然后,给我们自己开发的应用程序编写一个配置文件,让supervisor来管理它。

每个进程的配置文件都可以单独分拆,放在/etc/supervisor/conf.d/目录下,以.conf作为扩展名,

例如,forum.conf定义了一个gunicorn的进程

[program:forum]
command=gunicorn wsgi --bind 0.0.0.0:3000 --pid /tmp/forum.pid  这个在终端输入的命令
directory=/home/ubuntu/python/forum       执行文件的目录
autostart=true
autorestart=true

5. supervisorctl start forum 运行forum  查看状态

6.注意记得;给删掉,这个是注销的意思...     后缀改为 *.conf

 

posted @ 2017-12-29 22:01  cuzz_z  阅读(1780)  评论(0编辑  收藏  举报