我無法在nginx中配置日誌輪換。 我已經在使用Windows服務包裝的Windows機器上安裝了nginx服務。 我曾嘗試使用nginx重新打開日誌文件 - s重新打開,但命令給我錯誤。如何根據文件文件大小旋轉窗口的nginx日誌
0
A
回答
0
嘗試以下鏈接 Nginx loggging tips
0
Nginx的沒有任何內置模塊rolover日誌在Windows或其它任何平臺上,你可以重新打開nginx的日誌,如果你正在運行使用nginx的nginx.exe,但如果你正在運行使用已安裝的服務,你必須停止服務,然後旋轉日誌,然後再次啓動服務,
使用下面的批處理腳本Windows機器上旋轉nginx的錯誤日誌和訪問日誌nginx的
REM script to rotates nginx logs from java/windows cmd prompt
REM rolloverNginxLogs.bat [maxFileSize in bytes] [retainCount]
REM e.g rolloverNginxLogs.bat 10000 5
@echo off
setlocal EnableDelayedExpansion
pushd C:\nginx\logs
set ERRORLEVEL=0
set maxFileSize=%1
set retainCount=%2
set errorLogFile=error.log
set accessLogFile=access.log
set rotateAccessLogFile=""
set rotateErrorLogFile=""
set rotateFile=""
REM set current time, replace " " with "0" for hours less than 10
set currentTime=%time:~0,2%%time:~3,2%%time:~6,2%
if %currentTime% LSS 100000 (set currentTime=%currentTime: =0%)
REM check if access.log file rotation required
for %%A in (%accessLogFile%) do (
echo.Size of "%%A" is %%~zA bytes
if /I %%~zA GTR %maxFileSize% (
set rotateAccessLogFile=true
set rotateFile=true
)
)
REM check if error.log file rotation required
for %%A in (%errorLogFile%) do (
echo.Size of "%%A" is %%~zA bytes
if /I %%~zA GTR %maxFileSize% (
set rotateErrorLogFile=true
set rotateFile=true
)
)
REM if required rotate logs otherwise exit
if "%rotateFile%" EQU "true" (
goto ROTATELOG
) else (
goto DONE
)
:ROTATELOG
REM check whether the service is running if running then stop service
for /F "tokens=3 delims=: " %%H in ('sc query "nginx" ^| findstr "STATE"') do (
if /I "%%H" EQU "RUNNING" (
net stop "nginx"
)
)
REM rotate error log
if "%rotateErrorLogFile%" EQU "true" (
ren error.log error-%DATE%-%currentTime%.log
for /f "skip=%retainCount% eol=: delims=" %%F in ('dir /b /o-d /a-d error*.log') do @del "%%F"
)
REM rotate access log
if "%rotateAccessLogFile%" EQU "true" (
ren access.log access-%DATE%-%currentTime%.log
for /f "skip=%retainCount% eol=: delims=" %%F in ('dir /b /o-d /a-d access*.log') do @del "%%F"
)
REM check if the service is not running, start service
for /F "tokens=3 delims=: " %%H in ('sc query "nginx" ^| findstr "STATE"') do (
if /I "%%H" NEQ "RUNNING" (
echo starting nginx service
net start "nginx"
)
)
:DONE
popd
exit %ERRORLEVEL%
相關問題
- 1. 根據大小不旋轉日誌的旋轉日誌
- 2. 如何根據文件大小保持滾動日誌文件?
- 3. 如何按時旋轉日誌文件?
- 4. Log4j 1.2.17 - 如何根據文件大小執行日誌滾動
- 5. 根據大小和日期旋轉日誌的最佳方法
- 6. 日誌文件在旋轉後變成零大小
- 7. 根據日期將大日誌文件分割成更小的文件
- 8. MongoDB日誌文件大小
- 9. Nginx的日誌旋轉
- 10. log4net的:旋轉日誌文件名
- 11. 根據日誌大小,Logrotate不會自動旋轉
- 12. 日誌文件大小是巨大的
- 13. 根據瀏覽器窗口大小旋轉div
- 14. 手動旋轉log4j日誌文件
- 15. Python日誌記錄和旋轉文件
- 16. 日誌文件被損壞,在旋轉
- 17. Tomcat:log4j不會旋轉日誌文件
- 18. NLog旋轉和清理日誌文件
- 19. 如何根據窗口大小更新PyQt4小部件位置?
- 20. 刪除日誌文件窗口
- 21. MySQL日誌文件的性能/大小
- 22. iPhone中的日誌文件大小
- 23. 指定泊塢窗最大日誌JSON文件大小組合
- 24. 如何根據WPF中的窗口大小調整某個控件的大小?
- 25. 如何根據屏幕大小調整窗口小部件大小?
- 26. 如何在YII中設置日誌文件的最大大小?
- 27. kubernetes如何設置日誌文件的最大大小?
- 28. 如何根據文件大小顯示KB,MB或GB文件夾的大小?
- 29. 日誌文件的大小是否影響數據庫的性能?如何收縮日誌文件?
- 30. Django日誌旋轉和日誌文件所有權
謝謝!,但我認爲這個解決方案適用於centOS,我在windows平臺上配置了nginx。 –