ERP/server/gunicorn_config.py
2026-01-03 19:18:40 +08:00

47 lines
987 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Gunicorn配置文件
启用Keep-Alive、worker多进程和性能优化
"""
# 绑定地址和端口
bind = "0.0.0.0:5000"
# Worker进程配置
workers = 4 # 根据CPU核心数调整
worker_class = "sync"
worker_connections = 1000
max_requests = 1000
max_requests_jitter = 100
# Keep-Alive配置
keepalive = 5 # 保持连接5秒
timeout = 30
graceful_timeout = 30
# 日志配置
accesslog = "-"
errorlog = "-"
loglevel = "info"
# 性能优化
preload_app = True # 预加载应用
daemon = False
# 安全配置
limit_request_line = 4094
limit_request_fields = 100
limit_request_field_size = 8190
# 响应头优化
def post_fork(server, worker):
server.log.info("Worker spawned (pid: %s)", worker.pid)
def worker_exit(server, worker):
server.log.info("Worker exiting (pid: %s)", worker.pid)
# 当使用gunicorn时需要导入app
def on_starting(server):
server.log.info("Starting server with Keep-Alive enabled")