This article is a mirror article of machine translation, please click here to jump to the original article.

View: 27217|Reply: 2

[Web] Nginx log splitting and deletion

[Copy link]
Posted on 6/13/2020 10:52:07 PM | | | |
Requirements: Split the nginx logs according to the current date every day, one file per day, and delete files that are more than 30 days old, that is, only one month of logs are retained.

Write the nginx log splitting shell script as follows:

thereintologs_pathandpid_pathThe path should be added according to your actual situation.

You can see the path to the pid file in the nginx.conf file, or you can find it with the following command:

The command is briefly introduced

USR1 is also commonly used to inform applications to overload configuration files; For example, sending a USR1 signal to the Apache HTTP server will cause the following steps to occur: stop accepting new connections, wait for the current connection to stop, reload the configuration file, reopen the log file, restart the server, and thus achieve a relatively smooth non-shutdown change.

Upload the script file to your own server (whatever directory you want)

Grant script execution permissions



Test scripts


If an error is reported, you can refer to the following fixes:

/bin/bash^M: bad interpreter: No such file or directory
https://www.itsvse.com/thread-9258-1-1.html



Finally, install the crontab service and add a scheduled task!
Execute the log splitting script rule at 2 AM every day:

CentOS 7 uses crontab to perform tasks at regular intervals
https://www.itsvse.com/thread-9280-1-1.html

Attached is the sh script:

Tourists, if you want to see the hidden content of this post, pleaseReply





Previous:/bin/bash^M: bad interpreter: No such file or directory
Next:Practical configuration of NGINX High Availability Load Balancing
 Landlord| Posted on 6/12/2021 9:50:10 PM |
Configure log loops directly in the nginx configuration file without using logrotate or configuring cron tasks. You need to use the $time_iso8601 embed variable to get the time. $time_iso8601 format is as follows: 2015-08-07T18:12:02+02:00. Then use the regular expression to get the data for the required time.


 Landlord| Posted on 10/12/2025 7:27:12 PM |
Linux servers cut nginx logs based on logrotate
https://www.itsvse.com/thread-11088-1-1.html
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com