Ajout d'un logrotate pour les logs de nginx

This commit is contained in:
Jean-Marie Favreau 2025-04-28 12:05:06 +02:00
parent bfcc23c133
commit c3fbaac385
5 changed files with 42 additions and 5 deletions

2
.gitignore vendored
View File

@ -52,6 +52,7 @@ cover/
*.mo *.mo
*.pot *.pot
*.log *.log
*.log.*
local_settings.py local_settings.py
db.sqlite3 db.sqlite3
db.sqlite3-journal db.sqlite3-journal
@ -89,6 +90,7 @@ letsencrypt/
experimentations/cache/ experimentations/cache/
experimentations/cache-augustes.ical experimentations/cache-augustes.ical
experimentations/events-augustes.json experimentations/events-augustes.json
logs-nginx
# MacOS # MacOS
.DS_Store .DS_Store

View File

@ -0,0 +1,18 @@
FROM nginx:latest
RUN apt-get update && \
apt-get install -y logrotate cron && \
rm -rf /var/lib/apt/lists/*
RUN rm -f /var/log/nginx/access.log /var/log/nginx/error.log
RUN chmod 755 /var/log/nginx
RUN chown root:nginx /var/log/nginx
COPY deployment/scripts/nginx/nginx.logrotate /etc/logrotate.d/nginx
RUN chmod 644 /etc/logrotate.d/nginx
COPY deployment/scripts/nginx/entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
CMD ["/entrypoint.sh"]

View File

@ -0,0 +1,4 @@
#!/bin/bash
cron
nginx -g 'daemon off;'

View File

@ -0,0 +1,14 @@
/var/log/nginx/*.log {
su root nginx
daily
missingok
rotate 7
compress
delaycompress
notifempty
create 640 root nginx
sharedscripts
postrotate
[ -f /run/nginx.pid ] && kill -USR1 `cat /run/nginx.pid`
endscript
}

View File

@ -1,5 +1,3 @@
version: '3.7'
services: services:
backend: backend:
container_name: "${APP_NAME}-backend" container_name: "${APP_NAME}-backend"
@ -69,15 +67,16 @@ services:
command: [ "/bin/bash", "/app/deployment/scripts/wait-db.sh", "/app/deployment/scripts/celery/start-beat.sh" ] command: [ "/bin/bash", "/app/deployment/scripts/wait-db.sh", "/app/deployment/scripts/celery/start-beat.sh" ]
nginx: nginx:
image: nginx:latest
container_name: "${APP_NAME}-nginx" container_name: "${APP_NAME}-nginx"
build:
context: .
dockerfile: deployment/Dockerfile-nginx
volumes: volumes:
- ./deployment/scripts/nginx/nginx.conf:/etc/nginx/nginx.conf:ro - ./deployment/scripts/nginx/nginx.conf:/etc/nginx/nginx.conf:ro
- static_files:/usr/src/app/static - static_files:/usr/src/app/static
- media_files:/usr/src/app/media - media_files:/usr/src/app/media
- log_files:/var/log/nginx - ./logs-nginx:/var/log/nginx
env_file: .env.prod env_file: .env.prod
command: /bin/sh -c "rm /var/log/nginx/access.log /var/log/nginx/error.log && nginx -g 'daemon off;'"
ports: ports:
- 6380:80 - 6380:80
depends_on: depends_on: