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.