gunicorn Python部署應用

對於flask應用python

啓動命令爲 python app.pyflask

 

使用gunicorn啓動app

pip install gunicorndebug

python gunicorn --workers=7 switch_app:app -b 0.0.0.0:6002日誌

 

 

將gunicorn的配置參數寫入文件 config.py對象

python gunicorn -c config.py switch_app:app進程

其中switch_app爲文件名 switch_app.py  ,app爲文件中的app對象ip

 

 

config.py的代碼以下ssl

import os it

import gevent.monkey

gevent.monkey.patch_all()

import multiprocessing

#debug = True

loglevel = 'debug'

bind = "0.0.0.0:6002"

pidfile = "logs/gunicorn.pid"

accesslog = "logs/access.log"

errorlog = "logs/debug.log"

daemon = True

timeout = 180

#啓動進程數

workers=multiprocessing.cpu_count()

worker_class = 'gevent'

x_forwarded_for_header = 'X-FORWARDED-FOR'

 

 

其中timeout=180表示超過180秒未反應就關閉該請求響應,會獲得請求被異常關閉的日誌信息,默認超時時間爲60秒左右

相關文章
相關標籤/搜索