Home>Article>Backend Development> Use cronolog to cut nginx access logs and clean old logs regularly
This article mainly introduces the use of cronolog to cut nginx access logs and clean old logs regularly. It has certain reference value. Now I share it with you. Friends in need can refer to it
brew instal cronolog
If you encounter this error
sudo chown -Rwhoami:admin /usr/local/sbinIf there is no
/usr/local/sbinexecute this folder first
mkdir /usr/local/ sbin
Configure nginx access log
Start cronolog, When access.log.pipe generates data, use cronolog to transfer the data in access.log.pipe to access.log.%Y-%m-%d
Start or restart nginx
Clear old logs regularly
Save content
LOG_PATH="/usr/local/etc/nginx/logs" save_days=7 find $LOG_PATH -mtime +$save_days -exec rm -rf {} \;
Add scheduled execution task
crontab -eExecute at 0 o'clock every day
0 0 0 * * sh /usr/local/nginx/delete_nginx_logs.shThe above is the entire content of this article, I hope it will be useful for everyone's learning Help, please pay attention to the PHP Chinese website for more related content!
Related recommendations:
Location configuration method in Nginx##Use nginx to deploy multiple Web Servers on one server
The above is the detailed content of Use cronolog to cut nginx access logs and clean old logs regularly. For more information, please follow other related articles on the PHP Chinese website!