当前位置: 首页 > 工具软件 > Meinheld > 使用案例 >

flask+gunicorn+meinheld部署

鞠安民
2023-12-01

configm.py:

# -*-coding:utf-8 -*-

__author__ = "ZJL"

import multiprocessing

# 监听本机的5000端口
bind = '0.0.0.0:5000'

preload_app = True

# 开启进程
# workers=4
workers = multiprocessing.cpu_count() * 2 + 1

# 每个进程的开启线程
threads = multiprocessing.cpu_count() * 2

backlog = 2048

#工作模式为meinheld
worker_class = "egg:meinheld#gunicorn_worker"

# debug=True

# 如果不使用supervisord之类的进程管理工具可以是进程成为守护进程,否则会出问题
daemon = True

# 进程名称
proc_name = 'gunicorn.pid'

# 进程pid记录文件
pidfile = 'app_pid.log'

loglevel = 'debug'
logfile = 'debug.log'
accesslog = 'access.log'
access_log_format = '%(h)s %(t)s %(U)s %(q)s'

flasktest.py:

from flask import Flask
from werkzeug.contrib.fixers import ProxyFix

app = Flask(__name__)

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

#项目的代理设置
app.wsgi_app = ProxyFix(app.wsgi_app)
if __name__ == "__main__":
    app.run()

命令:gunicorn -c configm.py flasktest:app




 类似资料: