38 lines
No EOL
1.1 KiB
Python
38 lines
No EOL
1.1 KiB
Python
"""Gunicorn configuration.
|
|
|
|
All Gunicorn settings live here instead of the Dockerfile CMD so they can be
|
|
tweaked without rebuilding the image, and so the access-log format/timezone are
|
|
defined in one place.
|
|
"""
|
|
|
|
import os
|
|
import time
|
|
|
|
|
|
# ---- Server ----
|
|
bind = "0.0.0.0:8000"
|
|
workers = 2
|
|
|
|
# ---- Logging ----
|
|
accesslog = "-"
|
|
errorlog = "-"
|
|
capture_output = True
|
|
loglevel = "info"
|
|
|
|
# %(h)s = real client IP. Gunicorn resolves X-Forwarded-For based on its built-in
|
|
# proxy trust logic (the same mechanism already validated behind Traefik).
|
|
# %({Host}i)s = the Host header -> shows whether the request came via the
|
|
# legitimate domain (e.g. example.com) or directly via IP:port.
|
|
# %(t)s = overridden by CustomLogger -> [2026-08-09 20:41:00 +0300]
|
|
access_log_format = '%(h)s - %({Host}i)s - [%(t)s] "%(r)s" %(s)s %(b)s "%(f)s" "%(a)s"'
|
|
logger_class = "gunicorn_logger.CustomLogger"
|
|
|
|
# logger_class = CustomLogger
|
|
|
|
# ---- Timezone for Python logging / error logs ----
|
|
# Default to UTC unless TZ is set (e.g. TZ=Africa/Nairobi at docker run time).
|
|
os.environ.setdefault("TZ", os.environ.get("TZ", "UTC"))
|
|
try:
|
|
time.tzset()
|
|
except AttributeError: # non-Unix
|
|
pass |