diff --git a/Dockerfile b/Dockerfile index b85619f..0594a45 100644 --- a/Dockerfile +++ b/Dockerfile @@ -18,15 +18,20 @@ RUN --mount=type=cache,target=$POETRY_CACHE_DIR poetry install --no-root ### RUNTIME FROM python:3.12-bookworm as runtime +RUN apt-get update && \ + apt-get install -y nginx && \ + rm -rf /var/lib/apt/lists/* + ENV VIRTUAL_ENV=/app/.venv \ PATH="/app/.venv/bin:$PATH" \ PYTHONPATH="/contactform" \ - GUNICORN_CMD_ARGS="--workers=1 --bind=0.0.0.0:8000 --access-logfile=-" + GUNICORN_CMD_ARGS="--workers=1 --bind=unix:/app/gunicorn.sock --access-logfile=-" COPY --from=builder ${VIRTUAL_ENV} ${VIRTUAL_ENV} COPY contactform ./contactform +COPY nginx.conf /etc/nginx/nginx.conf -EXPOSE 8000 +EXPOSE 8080 -CMD ["gunicorn", "contactform.app:app"] \ No newline at end of file +CMD ["sh", "-c", "nginx && gunicorn contactform.app:app"] diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 0000000..384dab5 --- /dev/null +++ b/nginx.conf @@ -0,0 +1,48 @@ +worker_processes 1; + +user nobody nogroup; +error_log /var/log/nginx/error.log warn; +pid /var/run/nginx.pid; + +error_log /dev/stdout info; + +events { + worker_connections 1024; + accept_mutex off; +} + +http { + include mime.types; + + default_type application/octet-stream; + access_log /dev/stdout combined; + sendfile on; + + upstream app_server { + server unix:/app/gunicorn.sock fail_timeout=0; + } + + server { + listen 8080 deferred default_server; + client_max_body_size 4G; + + keepalive_timeout 5; + + # path for static files + root /contactform; + + location / { + # checks for static file, if not found proxy to app + try_files $uri @proxy_to_app; + } + + location @proxy_to_app { + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header Host $http_host; + proxy_redirect off; + proxy_pass http://app_server; + } + } +} \ No newline at end of file