From 789b07c7d1b0d056421e2b322cf856b32b34f9db Mon Sep 17 00:00:00 2001 From: Pier-Jean Malandrino Date: Thu, 30 Apr 2026 11:20:02 +0200 Subject: [PATCH] fix(nginx): make upload body size configurable via NGINX_MAX_BODY_SIZE env var nginx.conf was hard-capped at 5M, causing 413 on uploads larger than 5MB despite the backend accepting up to MAX_FILE_SIZE_MB (default 50). Both nginx configs become envsubst templates. NGINX_MAX_BODY_SIZE defaults to 200M so the backend application limit is always the effective arbiter. gettext-base added to the single-image apt deps to provide envsubst. --- .env.example | 4 ++++ Dockerfile | 10 ++++++---- docker-compose.yml | 2 ++ frontend/Dockerfile | 4 +++- frontend/{nginx.conf => nginx.conf.template} | 2 +- nginx.conf => nginx.conf.template | 2 +- 6 files changed, 17 insertions(+), 7 deletions(-) rename frontend/{nginx.conf => nginx.conf.template} (92%) rename nginx.conf => nginx.conf.template (92%) diff --git a/.env.example b/.env.example index d7f515c..e9457cf 100644 --- a/.env.example +++ b/.env.example @@ -18,6 +18,10 @@ # Max upload file size in MB (default: 50, 0 = unlimited) # MAX_FILE_SIZE_MB=50 +# Nginx body size limit — nginx format (default: 200M, 0 = unlimited). +# Must be >= MAX_FILE_SIZE_MB. Backend MAX_FILE_SIZE_MB is the effective arbiter. +# NGINX_MAX_BODY_SIZE=200M + # Max pages per PDF (default: 0 = unlimited). Set to 20 for HF Spaces. # MAX_PAGE_COUNT=0 diff --git a/Dockerfile b/Dockerfile index ff3e37b..5190af8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -24,10 +24,11 @@ FROM python:3.12-slim AS base ARG APP_VERSION=dev ENV APP_VERSION=${APP_VERSION} -# System deps: poppler (pdf2image), nginx +# System deps: poppler (pdf2image), nginx, gettext-base (envsubst for nginx template) RUN apt-get update && apt-get install -y --no-install-recommends \ poppler-utils \ nginx \ + gettext-base \ && rm -rf /var/lib/apt/lists/* # Python deps (common) @@ -41,8 +42,8 @@ COPY document-parser/ . # Frontend static files COPY --from=frontend-build /build/dist /usr/share/nginx/html -# Nginx config -COPY nginx.conf /etc/nginx/sites-enabled/default +# Nginx config (template — substituted at container start via envsubst) +COPY nginx.conf.template /etc/nginx/sites-enabled/default.template # Non-root user RUN useradd --create-home --shell /bin/bash appuser @@ -52,10 +53,11 @@ RUN mkdir -p /app/uploads /app/data && chown -R appuser:appuser /app ENV UPLOAD_DIR=/app/uploads ENV DB_PATH=/app/data/docling_studio.db +ENV NGINX_MAX_BODY_SIZE=200M EXPOSE 3000 -CMD ["sh", "-c", "nginx && exec su appuser -c 'uvicorn main:app --host 127.0.0.1 --port 8000'"] +CMD ["sh", "-c", "envsubst '${NGINX_MAX_BODY_SIZE}' < /etc/nginx/sites-enabled/default.template > /etc/nginx/sites-enabled/default && nginx && exec su appuser -c 'uvicorn main:app --host 127.0.0.1 --port 8000'"] # --- Remote: lightweight, delegates to Docling Serve --- FROM base AS remote diff --git a/docker-compose.yml b/docker-compose.yml index 6240ab2..d4022cf 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -117,6 +117,8 @@ services: context: ./frontend ports: - "3000:80" + environment: + NGINX_MAX_BODY_SIZE: ${NGINX_MAX_BODY_SIZE:-200M} depends_on: - document-parser diff --git a/frontend/Dockerfile b/frontend/Dockerfile index ea2b68a..cc8dc9e 100644 --- a/frontend/Dockerfile +++ b/frontend/Dockerfile @@ -9,6 +9,8 @@ RUN npm run build FROM nginx:alpine COPY --from=build /app/dist /usr/share/nginx/html -COPY nginx.conf /etc/nginx/conf.d/default.conf +COPY nginx.conf.template /etc/nginx/templates/default.conf.template + +ENV NGINX_MAX_BODY_SIZE=200M EXPOSE 80 diff --git a/frontend/nginx.conf b/frontend/nginx.conf.template similarity index 92% rename from frontend/nginx.conf rename to frontend/nginx.conf.template index d6b58a4..18e6e40 100644 --- a/frontend/nginx.conf +++ b/frontend/nginx.conf.template @@ -20,6 +20,6 @@ server { proxy_set_header X-Real-IP $remote_addr; proxy_read_timeout 900s; proxy_send_timeout 900s; - client_max_body_size 5M; + client_max_body_size ${NGINX_MAX_BODY_SIZE}; } } diff --git a/nginx.conf b/nginx.conf.template similarity index 92% rename from nginx.conf rename to nginx.conf.template index 20aa914..962d9d6 100644 --- a/nginx.conf +++ b/nginx.conf.template @@ -20,6 +20,6 @@ server { proxy_set_header X-Real-IP $remote_addr; proxy_read_timeout 900s; proxy_send_timeout 900s; - client_max_body_size 5M; + client_max_body_size ${NGINX_MAX_BODY_SIZE}; } }