Want to subscribe to topics you're interested in?
Become a Member

nginx access log retention

Discussion in 'System Administration' started by Rake-GH, Jan 21, 2021.

  1. Rake-GH

    Rake-GH Active Member

    179
    93
    28
    Jul 29, 2019
    USA
    Ratings:
    +144
    Local Time:
    2:18 PM
    default
    default
    in /home/nginx/domains/domainname/log it only lists 30 days of logs

    I want to keep logs permanently, what do I need to change?


    Thank you in advance.
     
  2. eva2000

    eva2000 Administrator Staff Member

    54,907
    12,240
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,811
    Local Time:
    4:18 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+

    Centmin Mod Log Rotation



    Centmin Mod should be auto log rotating your access and error logs via logrotate.

    You can modify how long you retain your nginx logs before the logs are rotated by logrtate at /etc/logrotate.d/nginx. Below examples rotate logs daily or whenever they hit 500MB in size, keeping the last 10 logs (rotate 10)

    Centmin Mod 123.09beta01's nginx log rotate would have the following log rotate config file /etc/logrotate.d/nginx contents if you server has more than 1153433 bytes of memory and more than 10485760 bytes of disk free space in /var partition
    Code (Text):
    /var/log/nginx/*.log /usr/local/nginx/logs/*.log /home/nginx/domains/*/log/*.log {
            daily
            dateext
            missingok
            rotate 10
            compress
            delaycompress
            notifempty
            postrotate
            /bin/kill -SIGUSR1 $(cat /usr/local/nginx/logs/nginx.pid 2>/dev/null) 2>/dev/null || true
            endscript          
    }
    

    If you server has less than 1153433 bytes of memory and less than 10485760 bytes of disk free space in /var partition
    Code (Text):
    /var/log/nginx/*.log /usr/local/nginx/logs/*.log /home/nginx/domains/*/log/*.log {
            daily
            dateext
            missingok
            rotate 10
            maxsize 500M
            compress
            delaycompress
            notifempty
            postrotate
            /bin/kill -SIGUSR1 $(cat /usr/local/nginx/logs/nginx.pid 2>/dev/null) 2>/dev/null || true
            endscript          
    }
    

    You can do a debug run of logrotate to see what happens when logrortate is meant to rotate your logs using SSH command
    Code (Text):
    logrotate -d /etc/logrotate.d/nginx
    
     
  3. Rake-GH

    Rake-GH Active Member

    179
    93
    28
    Jul 29, 2019
    USA
    Ratings:
    +144
    Local Time:
    2:18 PM
    default
    default
    Perfect thank you