gunicorn文档讨论了编辑配置文件,但我不知道它在哪里。
可能是一个简单的答案:)我在Amazon Linux AMI上。
答案 0 :(得分:23)
答案在gunicorn的文件中。 http://docs.gunicorn.org/en/latest/configure.html
您可以使用.ini或python脚本指定配置文件。
例如,来自django-skel项目
"""gunicorn WSGI server configuration."""
from multiprocessing import cpu_count
from os import environ
def max_workers():
return cpu_count()
bind = '0.0.0.0:' + environ.get('PORT', '8000')
max_requests = 1000
worker_class = 'gevent'
workers = max_workers()
您可以使用
运行服务器gunicorn -c gunicorn.py.ini project.wsgi
请注意,project.wsgi对应于wsgi的位置。
答案 1 :(得分:5)
示例文件位于:https://github.com/benoitc/gunicorn/blob/master/examples/example_config.py
你可以注释掉你不需要的东西,然后将Gunicorn指向它:
gunicorn -c config.py myproject:app
答案 2 :(得分:1)
默认配置是从site-packages/gunicorn/config.py
$ python -c "from distutils.sysconfig import get_python_lib; print('{}/gunicorn/config.py'.format(get_python_lib()))"
(output)
/somepath/flask/lib/python2.7/site-packages/gunicorn/config.py
您可以运行strace
来查看gunicorn
以什么顺序打开了哪些文件
gunicorn app:app -b 0.0.0.0:5000
$ strace gunicorn app:app -b 0.0.0.0:5000
stat("/somepath/flask/lib/python2.7/site-packages/gunicorn/config", 0x7ffd665ffa30) = -1 ENOENT (No such file or directory)
open("/somepath/flask/lib/python2.7/site-packages/gunicorn/config.so", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/somepath/flask/lib/python2.7/site-packages/gunicorn/configmodule.so", O_RDONLY) = -1 ENOENT (No
such file or directory)
open("/somepath/flask/lib/python2.7/site-packages/gunicorn/config.py", O_RDONLY) = 5
fstat(5, {st_mode=S_IFREG|0644, st_size=53420, ...}) = 0
open("/somepath/flask/lib/python2.7/site-packages/gunicorn/config.pyc", O_RDONLY) = 6
gunicorn -c g_config.py app:app
$ strace gunicorn -c g_config.py app:app
// in addition to reading default configs, reads '-c' specified config file
stat("g_config.py", {st_mode=S_IFREG|0644, st_size=6784, ...}) = 0
open("g_config.py", O_RDONLY)
创建本地gconfig.py
(任何名称)并仅定义要设置非默认值的变量,而不是在站点软件包中修改配置文件,因为始终会读取默认配置文件。
通过gunicorn -c gconfig.py
$ cat gconfig.py // (eg)
bind = '127.0.0.1:8000'
workers = 1
timeout = 60
. . .
或使用命令行选项代替配置文件:
gunicorn app:app -b 0.0.0.0:5000 -w 1 -t 60
gunicorn配置文件属性/标志: http://docs.gunicorn.org/en/stable/settings.html#settings
答案 3 :(得分:0)
就默认名称而言,Gunicorn将根据https://github.com/benoitc/gunicorn/blob/master/gunicorn/config.py#L518查找名为gunicorn.conf.py
的配置文件
答案 4 :(得分:0)
我在阅读文档后做到了这一点:
最后,我的Procfile就像:
网络:gunicorn app:app --timeout 600