From c35c4eade9733ba8e64a3c9decc167ffaa817ac7 Mon Sep 17 00:00:00 2001 From: puuu Date: Fri, 14 May 2021 14:03:42 +0900 Subject: [PATCH] Introduce ConfigurableWorker to make uvicorn respect FORCE_SCRIPT_NAME --- gunicorn.conf.py | 2 +- src/paperless/workers.py | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 src/paperless/workers.py diff --git a/gunicorn.conf.py b/gunicorn.conf.py index 995b4fb9d..bcc12490e 100644 --- a/gunicorn.conf.py +++ b/gunicorn.conf.py @@ -2,7 +2,7 @@ import os bind = '0.0.0.0:8000' workers = int(os.getenv("PAPERLESS_WEBSERVER_WORKERS", 2)) -worker_class = 'uvicorn.workers.UvicornWorker' +worker_class = 'paperless.workers.ConfigurableWorker' timeout = 120 def pre_fork(server, worker): diff --git a/src/paperless/workers.py b/src/paperless/workers.py new file mode 100644 index 000000000..4f2f0802a --- /dev/null +++ b/src/paperless/workers.py @@ -0,0 +1,11 @@ +import os +from uvicorn.workers import UvicornWorker +from django.conf import settings + +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "paperless.settings") + + +class ConfigurableWorker(UvicornWorker): + CONFIG_KWARGS = { + "root_path": settings.FORCE_SCRIPT_NAME or "", + }