Skip to content

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 –p parameter value

Trackbacks

No Trackbacks

Comments

Display comments as Linear | Threaded

Kilian on :

Thanks for your script, it helped me. First wanted to create a linux image and use that for my webserver, but your script saved the day.

Add Comment

You can use [geshi lang=lang_name [,ln={y|n}]][/geshi] tags to embed source code snippets.
Markdown format allowed
Form options