思路:每次关闭时,讲日志文件改名成日期时间相关的文件即可。因为 Nginx 启动时会自动生成日志文件。
bat代码如下:
cls@ECHO OFFSET NGINX_PATH=C:SET NGINX_DIR=C:\nginx-1.1.5\color 0aTITLE Nginx管理程序GOTO MENU:MENUCLSECHO.ECHO. * * * * Nginx Management * * *ECHO. * *ECHO. * 1 启动Nginx *ECHO. * *ECHO. * 2 关闭Nginx *ECHO. * *ECHO. * 3 重启Nginx *ECHO. * *ECHO. * 4 检查配置 *ECHO. * *ECHO. * 5 退 出 *ECHO. * *ECHO. * * * * * * * * * * * * * * * * *ECHO.ECHO.请输入命令编号:set /p ID=IF "%id%"=="1" GOTO cmd1IF "%id%"=="2" GOTO cmd2IF "%id%"=="3" GOTO cmd3IF "%id%"=="4" GOTO cmd4IF "%id%"=="5" EXITPAUSE:cmd1REM ------------- 启动PHP -------------@ECHO OFFSET PHP_FCGI_MAX_REQUESTS=1000ECHO.启动PHP FastCGI...%NGINX_PATH%CD %NGINX_DIR%RunHiddenConsole %NGINX_DIR%/php-5.3.8/php-cgi.exe -b 127.0.0.1:9000 -c %NGINX_DIR%/php-5.3.8/php.iniREM ------------- 启动Nginx -------------ECHO.启动Nginx......%NGINX_PATH%CD %NGINX_DIR%IF NOT EXIST %NGINX_DIR%nginx.exe ECHO %NGINX_DIR%nginx.exe不存在%NGINX_PATH%CD %NGINX_DIR%IF EXIST %NGINX_DIR% start %NGINX_DIR%nginx.exeECHO.OKPAUSEGOTO MENU:cmd2ECHO.REM ------------- 日志文件改名 -------------SET T1=%DATE:~0,4%.%DATE:~5,2%.%DATE:~8,2%.%time:~0,2%.%time:~3,2%.%time:~6,2%SET T2=%T1: =0%%NGINX_PATH%CD %NGINX_DIR%IF NOT EXIST %NGINX_DIR%logs\%T2%_ACCESS.log ren %NGINX_DIR%logs\access.log %T2%_ACCESS.log%NGINX_PATH%CD %NGINX_DIR%IF NOT EXIST %NGINX_DIR%logs\%T2%_ERROR.log ren %NGINX_DIR%logs\error.log %T2%_ERROR.logREM ------------- 关闭Nginx -------------ECHO.关闭Nginx......%NGINX_PATH%CD %NGINX_DIR%taskkill /F /IM nginx.exe > nulREM ------------- 关闭PHP -------------ECHO.关闭 PHP FastCGI...%NGINX_PATH%CD %NGINX_DIR%taskkill /F /IM php-cgi.exe > nulECHO.OKPAUSEGOTO MENU:cmd3ECHO.REM ------------- 关闭Nginx -------------ECHO.关闭Nginx......%NGINX_PATH%CD %NGINX_DIR%taskkill /F /IM nginx.exe > nulREM ------------- 关闭PHP -------------ECHO.关闭PHP FastCGI...%NGINX_PATH%CD %NGINX_DIR%taskkill /F /IM php-cgi.exe > nulECHO.OKGOTO cmd1GOTO MENU:cmd4ECHO.REM ------------- 检查Nginx配置 -------------ECHO.检查Nginx配置......%NGINX_PATH%CD %NGINX_DIR%IF NOT EXIST %NGINX_DIR%nginx.exe ECHO %NGINX_DIR%nginx.exe不存在%NGINX_PATH%CD %NGINX_DIR%IF EXIST %NGINX_DIR% %NGINX_DIR%nginx.exe -tECHO.完成检查PAUSEGOTO MENU
运行效果如下:
重新启动 Nginx 后: