简体   繁体   English

在 tmpfs 上使用 /var/log 的 Nginx

[英]Nginx with /var/log on tmpfs

I have the development machine set up to use tmpfs for /var/log.我已将开发机器设置为将 tmpfs 用于 /var/log。 Given that, at every boot the content is blank and gradually filled with whatever processes create while logging their guts.鉴于此,在每次启动时,内容都是空白的,并逐渐被记录他们的胆量时创建的任何进程填满。

The problem is (according to my interpretation of error messages): nginx is very reluctant to just create it's own log directory (/var/log/nginx in this case), so during start it keeps throwing the error at me:问题是(根据我对错误消息的解释):nginx 非常不愿意只创建自己的日志目录(在本例中为 /var/log/nginx),因此在启动期间它不断向我抛出错误:

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

As soon as I create the dir everything works just fine.一旦我创建目录,一切正常。 Is there a way to tell nginx to (at least attempt to) create the log dir?有没有办法告诉 nginx(至少尝试)创建日志目录?

As a first line of the do_start function in the script /etc/init.d/nginx, add the following command:作为脚本/etc/init.d/nginx中do_start函数的第一行,添加如下命令:

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

I don't like this solution but that's the easiest/quickest I found too.我不喜欢这个解决方案,但这也是我发现的最简单/最快的解决方案。

Regards问候

EDIT - If using Debian, the init.d script is a bit different.编辑 - 如果使用 Debian,init.d 脚本有点不同。 The "mkdir" line goes just after the line "start": “mkdir”行紧跟在“start”行之后:

start)
    mkdir -p /var/log/nginx

I realize this thread is older than dirt on an asteroid, but I wanted to include this answer here to provide for future generations of intrepid searchers so they could avoid the hours of toil I just put myself through.我意识到这个线程比小行星上的泥土还要古老,但我想在这里包含这个答案,以提供给未来勇敢的搜索者,这样他们就可以避免我刚刚让自己经历的辛劳时间。

If you get the messages:如果您收到以下消息:

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

Be sure your var/log folders are not set to be tmpfs!!!!确保你的 var/log 文件夹没有设置为 tmpfs!!! I had set mine that way to reduce writes to the SD card in my system, and that means every time nginx went to start, it couldn't find the logs or the nginx folder at /var/log/nginx - and so it fails and exits.我已经设置了这种方式来减少对系统中 SD 卡的写入,这意味着每次 nginx 启动时,它都无法在 /var/log/nginx 中找到日志或 nginx 文件夹 - 所以它失败了并退出。 If you see /var/log entered in /etc/fstab, comment it out, restart, manually create the nginx folder ONCE (I also manually created the error.log and access.log (blank files)) and restart nginx service.如果看到/etc/fstab 中输入了/var/log,将其注释掉,重启,手动创建nginx 文件夹ONCE(我也手动创建了error.log 和access.log(空白文件))并重启nginx 服务。 Your nginx server will run fine from then on (unless you do something else to break it, but that's for another thread).从那时起,您的 nginx 服务器将运行良好(除非您执行其他操作来破坏它,但那是针对另一个线程的)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM