Where is the Gunicorn config file?

The gunicorn documentation talks about editing the config files, but I have no idea where it is.

Probably a simple answer :) I'm on Amazon Linux AMI.


The answer is in the documentation of gunicorn. http://docs.gunicorn.org/en/latest/configure.html

You can specify the config file with .ini or a python script.

For example, from the django-skel project

"""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()

And you can run the server using

gunicorn -c gunicorn.py.ini project.wsgi

Note that project.wsgi correspond to the location of your wsgi.


An example file is here: https://github.com/benoitc/gunicorn/blob/master/examples/example_config.py

You can just comment out what you don't need and then point Gunicorn at it like so:

gunicorn -c config.py myproject:app

Default configs are read from 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

You can run strace to see what files, in what order are being opened by 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)

Instead of modifying the config file in site-packages, create a local gconfig.py (any name) and define only the variables you want to set non-default value since default config file is always read.

Pass as gunicorn -c gconfig.py

$ cat gconfig.py // (eg)
bind = '127.0.0.1:8000'
workers = 1
timeout = 60
. . .

or use command line options instead of a config file:

gunicorn app:app -b 0.0.0.0:5000 -w 1 -t 60

gunicorn config file attributes/flags: http://docs.gunicorn.org/en/stable/settings.html#settings