The method of LNMP one click installation script to periodically cut Nginx logs

Previously, the free bar introduced the one click installation of LNMP script for building the WEB website environment, and I have always liked to install it through the LNMP one click installation script of the military brother.

After the LNMP environment is built, website domain names are added. The website will run. During this process, nginx will record access logs. If you do not delete these nginx log files regularly, it will occupy a lot of hard disk space.

The author of the LNMP one click installation script actually wrote the corresponding script. In the tools folder under the LNMP directory, take the latest LNMP1.6 as an example /root/lnmp1.6/tools Directory.

The one click script for regularly cutting nginx logs is: cut_nginx_logs.sh

I will talk about moving this script to /root/ Directory, open this cut_nginx_logs.sh Scripts, modifying log_files_name And save_days Two parameters, needless to say, can be understood at a glance.

Add execution permission to Nginx log cutting script

chmod +x cut_nginx_logs.sh

Test whether the Nginx log cutting script can be executed normally

./cut_nginx_logs.sh

After execution, go to the/home/wwwlogs directory to view the file size change or modification time.

Using crontab to realize timing cutting log files

crontab -e

Enter the following:

00 00 * * * /root/cut_nginx_logs.sh

Note: 00 00 is the time minute/hour, which can be modified by yourself. For example, 10 12 * * * runs this script every day at 12.10 to continue nginx log cutting.

After the above steps, you can finish cutting Nginx log files regularly every day.

Copyright notice:
Author: Leisure Bar
Link: https://www.xianba.net/5092.html
Source: Xianba Resource Station
The copyright of this article belongs to the author. Please do not reprint it without permission.

THE END
share
QR code
< <Previous
Next>>