Gunicorn配置文件在哪里?

ken*_*ong 32 python flask gunicorn

gunicorn文档讨论了编辑配置文件,但我不知道它在哪里.

可能是一个简单的答案:)我在亚马逊Linux AMI上.

Arn*_*oly 26

答案在于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()
Run Code Online (Sandbox Code Playgroud)

您可以使用运行服务器

gunicorn -c gunicorn.py.ini project.wsgi
Run Code Online (Sandbox Code Playgroud)

请注意,project.wsgi对应于wsgi的位置.

  • 是的,但默认的是哪里? (17认同)
  • 您需要创建自己的。如果使用 Ubuntu,我建议使用 `/etc` 目录。 (3认同)
  • @Sekai的默认值请看[here](https://github.com/benoitc/gunicorn/blob/master/gunicorn/config.py)。例如,“ backlog”的默认值是[here](https://github.com/benoitc/gunicorn/blob/master/gunicorn/config.py#L561) (2认同)

bro*_*oot 7

读取默认配置 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
Run Code Online (Sandbox Code Playgroud)

您可以运行strace以查看正在打开哪些文件,按什么顺序打开gunicorn

gunicorn 应用程序:应用程序 -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
Run Code Online (Sandbox Code Playgroud)

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)
Run Code Online (Sandbox Code Playgroud)

不要修改站点包中的配置文件,而是创建一个本地gconfig.py(任何名称)并仅定义要设置非默认值的变量,因为始终读取默认配置文件。

通过作为 gunicorn -c gconfig.py

$ cat gconfig.py // (eg)
bind = '127.0.0.1:8000'
workers = 1
timeout = 60
. . .
Run Code Online (Sandbox Code Playgroud)

或使用命令行选项而不是配置文件:

gunicorn app:app -b 0.0.0.0:5000 -w 1 -t 60
Run Code Online (Sandbox Code Playgroud)

gunicorn 配置文件属性/标志:http ://docs.gunicorn.org/en/stable/settings.html#settings


iam*_*mbo 6

一个示例文件在这里:https : //github.com/benoitc/gunicorn/blob/master/examples/example_config.py

您可以注释掉不需要的内容,然后将Gunicorn指向它,如下所示:

gunicorn -c config.py myproject:app
Run Code Online (Sandbox Code Playgroud)


Joe*_*Joe 6

就默认名称而言,Gunicorn 将在执行 Gunicorn 的目录中查找命名的配置文件gunicorn.conf.py