flask+gunicorn+gevent+nginx 部署

1. 环境准备python2.7下

    (1)安装nginx 

      (2) 安装python

      (3) pip install gevent flask gunicorn

2. flask代码

#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
__title__ = ''
__author__ = ''
__mtime__ = '15/06/2017'
"""
from flask import Flask

app = Flask(__name__)


@app.route("/")
def main():
    return "hello world!"


if __name__ == '__main__':
    app.run()

3. gunicorn配置

cat gun.conf

import os
bind='127.0.0.1:5000'
workers=4
backlog=2048
worker_class="gevent" #sync, gevent,meinheld
daemon=True           # 是否后台运行
debug=True            
pidfile='./gunicore.pid'
loglevel='debug'     # debug error warning error critical
accesslog='log/gunicorn.log'
errorlog='log/gunicorn.err.log'

4. nginx 配置

cat /usr/local/nginx/conf/nginx.conf

# another virtual host using mix of IP-, name-, and port-based configuration
#
server {
     listen       80;
#    listen       somename:8080;
     server_name  localhost;

location / {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_pass http://127.0.0.1:5000;
        root   html;
        index  index.html index.htm;
    }
}

5. 运行

gunicorn -c gun.conf flaskr:app

6. 测试

time ab -n 1000 -c 100 http://127.0.0.1/

155410_BVFC_1406293.png

gunicorn 是多进程运行的1000个每100个并发执行大概1秒多

转载于:https://my.oschina.net/ayy/blog/967638

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值