Question

How to delete all log files containing visitors IP addresses every 24 hours?

Posted May 7, 2015 5.5k views
Nginx Ubuntu MySQL Server Optimization Security

I want to enforce strict privacy rules on my LEMP droplet and look for a way to automatically delete all log files that include my visitors data (IP address etc.) after a 24h period?

P.S.: I found a way to completely turn off IP logging but then fail2ban can’t protect my droplet anymore, so a 24h logging period seems like a good compromise.

1 comment
  • I would set up a cron job to run every 24 hours to delete the logs, access and error logs.

    find /var/log/nginx/* -mtime +1 -exec rm -rf {} \;
    

    If you type that into your terminal, you can test the command out first. If it works like you want, it will remove all of the files in that folder older than 1 day, then set up a cron job to run every 24 hours.

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

1 answer

This question was answered by @brass:

I would set up a cron job to run every 24 hours to delete the logs, access and error logs.

find /var/log/nginx/* -mtime +1 -exec rm -rf {} \;

If you type that into your terminal, you can test the command out first. If it works like you want, it will remove all of the files in that folder older than 1 day, then set up a cron job to run every 24 hours.

View the original comment

Submit an Answer