fix nginx media serve

This commit is contained in:
godd0t 2023-05-10 16:06:30 +02:00
parent dcbc68d26a
commit b5b64ab7f3
3 changed files with 31 additions and 19 deletions

View File

@ -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/;
}
}
}

View File

@ -3,8 +3,6 @@ events {}
http { http {
include /etc/nginx/mime.types; include /etc/nginx/mime.types;
default_type application/octet-stream; default_type application/octet-stream;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
server { server {
listen 80; listen 80;
@ -13,12 +11,4 @@ http {
alias /usr/src/app/static/; alias /usr/src/app/static/;
} }
} }
server {
listen 80;
location /media {
autoindex on;
alias /usr/src/app/media/;
}
}
} }

View File

@ -67,20 +67,29 @@ services:
container_name: "${APP_NAME}-celery-beat" container_name: "${APP_NAME}-celery-beat"
command: [ "/bin/sh", "/app/deployment/scripts/celery/start-beat.sh" ] command: [ "/bin/sh", "/app/deployment/scripts/celery/start-beat.sh" ]
nginx: nginx-static:
image: nginx:latest image: nginx:latest
container_name: "${APP_NAME}-nginx" container_name: "${APP_NAME}-nginx-static"
volumes: 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 - 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 - media_files:/usr/src/app/media
labels: labels:
- "traefik.enable=true" - "traefik.enable=true"
- "traefik.http.routers.${APP_NAME}-nginx.rule=Host(`${APP_HOST}`) && (PathPrefix(`/static`) || PathPrefix(`/media`))" - "traefik.http.routers.${APP_NAME}-nginx-media.rule=Host(`${APP_HOST}`) && PathPrefix(`/media`)"
- "traefik.http.routers.${APP_NAME}-nginx.entrypoints=web" - "traefik.http.routers.${APP_NAME}-nginx-media.entrypoints=web"
- "traefik.http.services.${APP_NAME}-nginx.loadbalancer.server.port=80" - "traefik.http.services.${APP_NAME}-nginx-media.loadbalancer.server.port=80"
depends_on:
- backend
traefik: traefik:
image: traefik:v2.5 image: traefik:v2.5
@ -91,7 +100,6 @@ services:
- "--entrypoints.web.address=:80" - "--entrypoints.web.address=:80"
- "--entrypoints.web-secure.address=:443" - "--entrypoints.web-secure.address=:443"
- "--log.level=DEBUG" - "--log.level=DEBUG"
- "--log.format=json"
- "--log.filePath=/logs/traefik.log" - "--log.filePath=/logs/traefik.log"
- "--accesslog=true" - "--accesslog=true"
- "--accesslog.filePath=/logs/access.log" - "--accesslog.filePath=/logs/access.log"