将nginx access_log和error_log日志记录到主进程的STDOUT和STDERR [英] Have nginx access_log and error_log log to STDOUT and STDERR of master process

查看:637
本文介绍了将nginx access_log和error_log日志记录到主进程的STDOUT和STDERR的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以将主进程日志记录到STDOUT STDERR而不是文件中?

Is there a way to have the master process log to STDOUT STDERR instead of to a file?

似乎您只能将文件路径传递给access_log指令:

It seems that you can only pass a filepath to the access_log directive:

access_log  /var/log/nginx/access.log

error_log也是如此:

And the same goes for error_log:

error_log /var/log/nginx/error.log

我知道这可能不是nginx的功能,例如,我会对使用tail的简洁解决方案感兴趣.尽管它最好来自主进程,因为我在前台运行nginx.

I understand that this simply may not be a feature of nginx, I'd be interested in a concise solution that uses tail, for example. It is preferable though that it comes from the master process though because I am running nginx in the foreground.

推荐答案

编辑:似乎nginx现在支持error_log stderr;,如

it seems nginx now supports error_log stderr; as mentioned in Anon's answer.

您可以将日志发送到/dev/stdout.在nginx.conf:

You can send the logs to /dev/stdout. In nginx.conf:

daemon off;
error_log /dev/stdout info;

http {
  access_log /dev/stdout;
  ...
}

可能需要运行 ln -sf/proc/self/fd/dev/如果使用运行某些Docker容器,则使用/dev/fd/1/dev/fd/2

edit: May need to run ln -sf /proc/self/fd /dev/ if using running certain docker containers, then use /dev/fd/1 or /dev/fd/2

这篇关于将nginx access_log和error_log日志记录到主进程的STDOUT和STDERR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆