Scheduled splitting of nginx logs in Windows

Source: Internet
Author: User
Nginx log files are very important for friends who want to make IP/PV statistics. Nginx has never been used in windows before. In the past two days, due to business needs, nginx is used as a server cluster in windows, it is found that logs cannot be split by time in nginx for Windows. in Linux, this function is generally implemented through shell scripts. I found a solution for splitting nginx logs in windows on the Internet, but I did not find a suitable solution. So I wrote a simple batch processing method to implement this small function. Code Put it below for your convenience. The default log source file path is D: \ data1 \ logs \ www. log. The destination path is D: \ data1 \ logs2 \ to create a BAT file. The content is as follows: Taskkill /F/IM nginx.exe

 

Set"Required STR = move D: \ data1 \ logs \ www. Log D: \ data1 \ logs2 \ access_ydgdw_211.138.195.36_log. % Date :~ 0, 4%-% Date :~ 5, 2%-% Date :~ 8, 2%. Log
Call % response STR %"

Start Save nginx and put the batch file in the nginx root directory, add a task scheduler in windows and execute it once a day. the batch processing involves three tasks: killing the running nginx process in the system, backing up the nginx process, renaming the log file based on the time, and starting the nginx service. After testing, logs can be backed up only when the nginx service is stopped under Windows. This is a little pity, but generally the backup process will be completed within 1 to 2 seconds, put the batch processing in the morning at around two o'clock every day, basically does not affect nginx service provision.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.