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

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

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.

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

Have another answer? Share your knowledge.