From 32276412fce1bc360978e3d43ffa7c2c1c89710d Mon Sep 17 00:00:00 2001 From: godd0t Date: Wed, 10 May 2023 15:53:47 +0200 Subject: [PATCH 1/3] fix nginx media serve --- deployment/scripts/nginx/nginx.conf | 9 +++++++-- docker-compose.prod.yml | 5 ++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/deployment/scripts/nginx/nginx.conf b/deployment/scripts/nginx/nginx.conf index 9c246a3..cced7f6 100644 --- a/deployment/scripts/nginx/nginx.conf +++ b/deployment/scripts/nginx/nginx.conf @@ -8,9 +8,14 @@ http { server { listen 80; - location ~ ^/(images|javascript|js|css|flash|media|static)/ { + location /static { autoindex on; - alias /usr/src/app/; + alias /usr/src/app/static/; + } + + location /media { + autoindex on; + alias /usr/src/app/media/; } } } diff --git a/docker-compose.prod.yml b/docker-compose.prod.yml index 231fd6b..9627240 100644 --- a/docker-compose.prod.yml +++ b/docker-compose.prod.yml @@ -76,7 +76,7 @@ services: - media_files:/usr/src/app/media labels: - "traefik.enable=true" - - "traefik.http.routers.${APP_NAME}-nginx.rule=Host(`${APP_HOST}`) && (PathPrefix(`/static`) && PathPrefix(`/media`))" + - "traefik.http.routers.${APP_NAME}-nginx.rule=Host(`${APP_HOST}`) && (PathPrefix(`/static`) || PathPrefix(`/media`))" - "traefik.http.routers.${APP_NAME}-nginx.entrypoints=web" - "traefik.http.services.${APP_NAME}-nginx.loadbalancer.server.port=80" depends_on: @@ -90,6 +90,9 @@ services: - "--providers.docker.exposedbydefault=false" - "--entrypoints.web.address=:80" - "--entrypoints.web-secure.address=:443" + - "--log.level=DEBUG" + - "--log.format=json" + - "--log.filePath=/logs/traefik.log" - "--accesslog=true" - "--accesslog.filePath=/logs/access.log" - "--certificatesresolvers.letsencrypt.acme.email=${LETSENCRYPT_EMAIL}" From dcbc68d26a1efbef5909f81d6ec8630ccfd5d87f Mon Sep 17 00:00:00 2001 From: godd0t Date: Wed, 10 May 2023 16:02:24 +0200 Subject: [PATCH 2/3] fix nginx media serve --- deployment/scripts/nginx/nginx.conf | 3 +++ 1 file changed, 3 insertions(+) diff --git a/deployment/scripts/nginx/nginx.conf b/deployment/scripts/nginx/nginx.conf index cced7f6..4a87375 100644 --- a/deployment/scripts/nginx/nginx.conf +++ b/deployment/scripts/nginx/nginx.conf @@ -12,7 +12,10 @@ http { autoindex on; alias /usr/src/app/static/; } + } + server { + listen 80; location /media { autoindex on; alias /usr/src/app/media/; From b5b64ab7f313a0c72ef24b27cf75fd1e6ba46365 Mon Sep 17 00:00:00 2001 From: godd0t Date: Wed, 10 May 2023 16:06:30 +0200 Subject: [PATCH 3/3] fix nginx media serve --- deployment/scripts/nginx/nginx-media.conf | 14 ++++++++++ .../nginx/{nginx.conf => nginx-static.conf} | 10 ------- docker-compose.prod.yml | 26 ++++++++++++------- 3 files changed, 31 insertions(+), 19 deletions(-) create mode 100644 deployment/scripts/nginx/nginx-media.conf rename deployment/scripts/nginx/{nginx.conf => nginx-static.conf} (51%) diff --git a/deployment/scripts/nginx/nginx-media.conf b/deployment/scripts/nginx/nginx-media.conf new file mode 100644 index 0000000..50cd6a5 --- /dev/null +++ b/deployment/scripts/nginx/nginx-media.conf @@ -0,0 +1,14 @@ +events {} + +http { + include /etc/nginx/mime.types; + default_type application/octet-stream; + + server { + listen 80; + location /media { + autoindex on; + alias /usr/src/app/media/; + } + } +} diff --git a/deployment/scripts/nginx/nginx.conf b/deployment/scripts/nginx/nginx-static.conf similarity index 51% rename from deployment/scripts/nginx/nginx.conf rename to deployment/scripts/nginx/nginx-static.conf index 4a87375..567f375 100644 --- a/deployment/scripts/nginx/nginx.conf +++ b/deployment/scripts/nginx/nginx-static.conf @@ -3,8 +3,6 @@ events {} http { include /etc/nginx/mime.types; default_type application/octet-stream; - access_log /var/log/nginx/access.log; - error_log /var/log/nginx/error.log; server { listen 80; @@ -13,12 +11,4 @@ http { alias /usr/src/app/static/; } } - - server { - listen 80; - location /media { - autoindex on; - alias /usr/src/app/media/; - } - } } diff --git a/docker-compose.prod.yml b/docker-compose.prod.yml index 9627240..6627e85 100644 --- a/docker-compose.prod.yml +++ b/docker-compose.prod.yml @@ -67,20 +67,29 @@ services: container_name: "${APP_NAME}-celery-beat" command: [ "/bin/sh", "/app/deployment/scripts/celery/start-beat.sh" ] - nginx: + nginx-static: image: nginx:latest - container_name: "${APP_NAME}-nginx" + container_name: "${APP_NAME}-nginx-static" volumes: - - ./deployment/scripts/nginx/nginx.conf:/etc/nginx/nginx.conf:ro + - ./deployment/scripts/nginx/nginx-static.conf:/etc/nginx/nginx.conf:ro - static_files:/usr/src/app/static + labels: + - "traefik.enable=true" + - "traefik.http.routers.${APP_NAME}-nginx-static.rule=Host(`${APP_HOST}`) && PathPrefix(`/static`)" + - "traefik.http.routers.${APP_NAME}-nginx-static.entrypoints=web" + - "traefik.http.services.${APP_NAME}-nginx-static.loadbalancer.server.port=80" + + nginx-media: + image: nginx:latest + container_name: "${APP_NAME}-nginx-media" + volumes: + - ./deployment/scripts/nginx/nginx-media.conf:/etc/nginx/nginx.conf:ro - media_files:/usr/src/app/media labels: - "traefik.enable=true" - - "traefik.http.routers.${APP_NAME}-nginx.rule=Host(`${APP_HOST}`) && (PathPrefix(`/static`) || PathPrefix(`/media`))" - - "traefik.http.routers.${APP_NAME}-nginx.entrypoints=web" - - "traefik.http.services.${APP_NAME}-nginx.loadbalancer.server.port=80" - depends_on: - - backend + - "traefik.http.routers.${APP_NAME}-nginx-media.rule=Host(`${APP_HOST}`) && PathPrefix(`/media`)" + - "traefik.http.routers.${APP_NAME}-nginx-media.entrypoints=web" + - "traefik.http.services.${APP_NAME}-nginx-media.loadbalancer.server.port=80" traefik: image: traefik:v2.5 @@ -91,7 +100,6 @@ services: - "--entrypoints.web.address=:80" - "--entrypoints.web-secure.address=:443" - "--log.level=DEBUG" - - "--log.format=json" - "--log.filePath=/logs/traefik.log" - "--accesslog=true" - "--accesslog.filePath=/logs/access.log"