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

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.

Show comments

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

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.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

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