suntsu.ch

Setup logrotate for nginx under windows

Create a batch script for the logrotate and save it as nginx_logrotate.bat

rem get date in format ddMMyyyyhhmmss
set dt=%DATE:~6,4%%DATE:~3,2%%DATE:~0,2%%TIME:~0,2%%TIME:~3,2%%TIME:~6,2%
set dt=%dt: =0%
rem move the current logfiles
move F:\Programme\nginx\logs\Access.log F:\Programme\nginx\logs\Access%dt%.log
move F:\Programme\nginx\logs\Error.log F:\Programme\nginx\logs\Error%dt%.log
rem tell nginx to write new logfiles
cd F:\Programme\nginx\
call F:\Programme\nginx\nginx.exe -p F:\Programme\nginx\ -s reopen
Then you can create a basic windows scheduler task which starts this batch script.

If you run nginx as a windows service, make sure to execute the windows scheduler with the same user as the nginx windows service is running.

When you’re getting the following error: could not open error log file: CreateFile() “F:\Programme\nginx\nginx.exe/logs/error.log” failed (3: The system cannot find the path specified), make sure to not add nginx.exe to the parameter value