From e0318afc93ee3bd8309f89941fd46c902203ac79 Mon Sep 17 00:00:00 2001 From: fsoest Date: Wed, 1 Jan 2025 23:37:54 +0100 Subject: [PATCH] Nginx for static files --- Dockerfile | 5 ++++- config/default.conf | 15 +++++++++++++++ init.sh | 4 +++- 3 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 config/default.conf diff --git a/Dockerfile b/Dockerfile index 02b665f..c76d501 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,9 +10,12 @@ RUN pip3 install -r requirements.txt COPY . . -EXPOSE 8016 +EXPOSE 80 RUN chmod +x ./init.sh RUN chmod +x S1/initial_setup.sh +RUN apk add --no-cache nginx +COPY config/default.conf /etc/nginx/http.d/default.conf + CMD ["/bin/sh", "-c", "./init.sh"] \ No newline at end of file diff --git a/config/default.conf b/config/default.conf new file mode 100644 index 0000000..b3e346c --- /dev/null +++ b/config/default.conf @@ -0,0 +1,15 @@ +server { + listen 80 default_server; + + location /static/ { + alias /opt/s1/S1/staticfiles/; + autoindex off; + + expires 3M; # Cache for 3 months + add_header Cache-Control "public, max-age=31536000, immutable"; + } + + location / { + proxy_pass http://127.0.0.1:8016; + } +} \ No newline at end of file diff --git a/init.sh b/init.sh index 187d1ef..d7532fb 100644 --- a/init.sh +++ b/init.sh @@ -1,3 +1,5 @@ +nginx -g "daemon on;" + crontab cron_schedule && crond cd S1 && python manage.py collectstatic -cd S1 && gunicorn S1.wsgi --bind 0.0.0.0:8016 \ No newline at end of file +gunicorn S1.wsgi --bind 0.0.0.0:8016 \ No newline at end of file