Nginx+gunicorn + Flask負載均衡配置

nginx版本:1.12.2,gunicorn和flask都是用pip安裝的nginx

1.nginx.conf內容
worker_processes  1;
events {
    worker_connections  1024;
}web

http {
    include       mime.types;
    default_type  application/octet-stream;flask

    sendfile        on;
    keepalive_timeout  65;app

     upstream servers{
        server 127.0.0.1:8888;
        server 127.0.0.1:8889;
    }
    server {
        listen       80;
        server_name  localhost;webapp

        location / {
            proxy_pass http://servers;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }
    }
}url


2用gunicorn啓動Flask: gunicorn -b127.0.0.1:8888 webapp:app -Dserver

webapp.py內容
# -*- coding:utf-8 -*-
from flask import Flask, request, render_template, url_forip


app = Flask(__name__, static_folder="static", template_folder='templates')
logger = app.loggerutf-8


@app.route("/")
def index():
    return "Hello"rem

相關文章
相關標籤/搜索