2012-05-08 31 views
1

我有開發機器設置爲使用tmpfs/var/log。鑑於此,在每次啓動時,內容都是空白的,並逐漸填充任何進程在記錄其膽量時創建的內容。 (根據我對錯誤消息的解釋):nginx非常不願意創建自己的日誌目錄(在這種情況下爲/ var/log/nginx),所以在開始時它一直在向我拋出錯誤:Nginx的/ var /登錄tmpfs

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok 
2012/05/08 21:42:35 [emerg] 2368#0: open() "/var/log/nginx/error.log" failed (2: No such file or directory) 
nginx: configuration file /etc/nginx/nginx.conf test failed 

一旦我創建了dir,一切正常。 有沒有辦法告訴nginx(至少嘗試)創建日誌目錄?

+0

將它創建爲初始化腳本的一部分? –

+0

剛剛發生在我身上,解決方案非常簡單,就像在/etc/init.d/nginx腳本中添加3行代碼一樣。 :)對不起,沒有時間佔用你的時間。 :] – topp

+0

請回答您自己的問題或更改標題以反映其解決。謝謝 –

回答

3

按照腳本/etc/init.d/nginx的do_start函數的第一行,添加下面的命令:

# Create the folder "nginx" in /var/log otherwise nginx can't start 
mkdir -p /var/log/nginx 

我不喜歡這樣的解決方案,但是這是最簡單的/最快的我也發現了。

問候

編輯 - 如果使用Debian,該腳本init.d中是一個有點不同。 「mkdir」行在「start」行之後:

start) 
    mkdir -p /var/log/nginx 
+1

如果您在Debian上使用systemd,您必須將其添加到'nginx.service'文件(您可以通過運行'systemctl show nginx.service | grep FragmentPath'找到它)。你必須在ExecStartPre =/usr/bin/nginx -t ...行之前添加'ExecStartPre =/bin/mkdir -p/var/log/nginx'(因爲這樣會在啓動前測試配置,如果找不到目錄,它將會失敗。) 如果在運行/etc/init.d/nginx時得到'Starting nginx(通過systemctl)...',系統將使用systemd。 – matega