应用工具集: flask + gunicorn + gevent + 1. flask 应用 app.py from flask import Flask app = Flask(__name__) @app.route('/') def index(): return "hello flask" if __name__ == '__main__': app.run() 安装 gunicorn
应用工具集:
flask + gunicorn + gevent +1. flask 应用
- app.py
app = Flask(__name__)
@app.route('/')
def index():
return "hello flask"
if __name__ == '__main__':
app.run()
安装 gunicorn并配置gun.conf文件
# 安装pip install gunicorn
# gun.conf
import os
bind = '0.0.0.0:9000'
workers = 4
backlog = 2048 # 监听队列
worker_class = "gevent" #使用gevent模式,还可以使用sync 模式,默认的是sync模式
debug = True
chdir = '/Users/ztc/www/python/project01/' #你项目的根目录,比如我的app.py文件在/home/ubuntu/app目录下,就填写'/home/ubuntu/app'
proc_name = 'gunicorn.proc'
多实例启动flask应用
gunicorn -k gevent -c gun.conf app:app配置nginx
server{listen 80;
server_name www.app.com; # 域名
location / {
proxy_pass http://127.0.0.1:9000;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
重启nginx
nginx -s reload