brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: mount your own logrotate file in Nginx Proxy Manager when access logs grow

Nginx
~/tips/tip-nginxproxymanager-custom-logrotate

services:

Replaces the default weekly log rotation of Nginx Proxy Manager with your own file.

Access logs on a busy proxy grow faster than I expect, and the default rotation is weekly. Nginx Proxy Manager lets you replace the rotation file with your own.

According to the Nginx Proxy Manager documentation, NPM rotates the access and error logs weekly and keeps 4 and 10 log files respectively. Depending on usage that can mean large files, especially for access logs. The docs describe customising it with a mount: your own file goes to /etc/logrotate.d/nginx-proxy-manager inside the container.

services:
  app:
    image: jc21/nginx-proxy-manager:latest
    volumes:
      - /mnt/user/appdata/npm/data:/data
      - /mnt/user/appdata/npm/logrotate.custom:/etc/logrotate.d/nginx-proxy-manager

Start from the default file, which lives in the NPM repository. The access log block looks like this there:

/data/logs/*_access.log /data/logs/*/access.log {
    su npm npm
    create 0644
    weekly
    rotate 4
    missingok
    notifempty
    compress
    sharedscripts
    postrotate
    kill -USR1 `cat /run/nginx/nginx.pid 2>/dev/null` 2>/dev/null || true
    endscript
}

I would copy the whole default file into logrotate.custom and change only the numbers. For example, swap weekly for size 50M (the default file already uses a size line for backend.log) and lower rotate if disk space matters. Keep the postrotate part: nginx logs rotate by renaming the files and then sending the master process a USR1 signal, which makes it reopen its log files, as the nginx control documentation describes.

The caveat is that your file replaces the default one completely, it does not add to it. Leave out the error log block or the backend.log block and those logs are no longer rotated. Compare against the default of the image version you run, since I only looked at the current repository file.

Pin the image to a version you have tested, as the file may differ between releases.

Further reading: Nginx Proxy Manager advanced configuration, Default logrotate file in the NPM repository, Controlling nginx

Going deeper: Guide: fix a 502 Bad Gateway in Nginx Proxy Manager, with a checklist that finds the cause

More Nginx tips sudo certbot --nginx -d example.com -d www.example.com /data/nginx/custom/server_redirect.conf map $http_upgrade $connection_upgrade { proxy_intercept_errors on; proxy_redirect http://localhost:3000/ /app/; All Nginx tips (50) All topics

Link