The same NGINX but with logs compression, rotation and retention.
Every midnight new access and error log files start, the previous day's logs will be compressed. All compressed logs older than one week will be deleted.
All logs are stored in the directory /var/log/nginx/.
-
/var/log/nginx/access.log- current access logs -
/var/log/nginx/error.log- current error logs -
/var/log/nginx/job.log- logs of the cron job -
/var/log/nginx/archive/- directory with compressed logs
$ docker build -t logged-nginx .
$ docker volume create nginx_log
$ docker run --name logged-nginx \
--restart unless-stopped \
-v $(pwd)/nginx.conf:/etc/nginx/nginx.conf \
-v nginx_log:/var/log/nginx \
-p 80:80 \
-d logged-nginx:latest$ docker-compose build
$ docker-compose upCheck the nginx is working:
$ curl -X GET localhost:80
> Hello, World!Show the cron job logs:
$ docker exec logged-nginx tail /var/log/nginx/job.logSearch with grep in today's access logs:
$ docker exec logged-nginx grep '"GET / HTTP/1.1" 200' /var/log/nginx/access.logSearch with zgrep in all archived logs:
$ docker exec logged-nginx bash -c 'find /var/log/nginx/archive/*.log.gz | xargs zgrep "http://localhost/"'