Have nginx access_log and error_log log to STDOUT and STDERR of master process

quinn picture quinn · Mar 20, 2014 · Viewed 133.4k times · Source

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

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

access_log  /var/log/nginx/access.log

And the same goes for error_log:

error_log /var/log/nginx/error.log

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.

Answer

Patrick picture Patrick · Apr 27, 2014

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

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

daemon off;
error_log /dev/stdout info;

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

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