如何更改 nginx 臨時和日誌資料夾或完全停用日誌記錄

如何更改 nginx 臨時和日誌資料夾或完全停用日誌記錄

我在 Windows 7 下運行 nginx 1.3.5,我需要直接從只讀媒體(CD 或 DVD)執行 nginx,但是當我想運行它時,它失敗並出現以下錯誤:

nginx: [alert] could not open error log file: CreateFile() "logs/error.log" fail
ed (5: Access is denied)
2012/08/28 13:52:46 [emerg] 5604#2864: CreateDirectory() "J:\nginx-1.3.5/temp/client_body_temp" failed (5: Access is denied)

其中 J 是我的 CD-ROM 磁碟機代號。
我已經更改了nginx.conf 以完全禁用日誌記錄,但似乎它仍然嘗試在“/logs”資料夾中建立一個名為“error.log”的文件,並在啟動時在“/temp”資料夾中建立一些額外的臨時內容,所以我想將“logs”和“temp”目錄路徑更改為 Windows 臨時資料夾 (%temp%),但我不知道該怎麼做。
另外我想知道為什麼 nginx 在禁用錯誤日誌記錄後仍然創建“logs/error.log”?

答案1

http://nginx.org/en/docs/http/ngx_http_log_module.html列出了用於控制日誌記錄的指令,具體來說有以下 2 個:

syntax:     access_log path [format [buffer=size]]; 
            access_log off;
default:    access_log logs/access.log combined;
context:    http, server, location, if in location, limit_except

syntax:     error_log file | stderr [debug | info | notice | warn | error | crit | alert | emerg];
default:    error_log logs/error.log error;
context:    main, http, server, location 

因此,雖然您可以完全停用 access_log,但 error_log 似乎並非如此。儘管如此,你仍然可以透過將以下內容加入你的 nginx 配置中來達到你想要的效果;

error_log /dev/null emerg; #redirect the logging we can't shut off to a black hole;
acces_log off; #disable acces log

更新:剛剛注意到 windows 標籤,請參閱這個問題對於 Windows /dev/null 等效項

答案2

據我所知,您可以停用訪問日誌,但不能停用錯誤日誌。 Nginx 正在嘗試建立/寫入訊息到位於 CD/DVD 上的日誌檔案中。嘗試將日誌目錄設定到 HD 分割區,例如 C: 或 D:

相關內容