I want to redirect nginx access logs to stdout
to be able to analyze them through journalctl
(systemd).
There is the same question with approved answer.
Have nginx access_log and error_log log to STDOUT and STDERR of master process
But it does not work for me. With /dev/stderr
I get open() "/dev/stderr" failed (6: No such device or address)
. With /dev/stdout
I get no access logs in journalctl -u nginx
.
nginx.conf
daemon off;
http {
access_log /dev/stdout;
error_log /dev/stdout;
...
}
...
sitename.conf
server {
server_name sitename.com;
root /home/username/sitename.com;
location / {
proxy_pass http://localhost:3000/;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
access_log on;
}
}
nginx.service
[Service]
Type=forking
PIDFile=/run/nginx.pid
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=nginx
ExecStartPre=/usr/sbin/nginx -t -q -g 'master_process on;'
ExecStart=/usr/sbin/nginx -g 'master_process on;'
ExecReload=/usr/sbin/nginx -g 'master_process on;' -s reload
ExecStop=-/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 --pidfile /run/nginx.pid
TimeoutStopSec=5
I've tried my best to workaround that by changing every possible parameter in the code above and with different nginx versions (1.2, 1.6) but without any success.
I'm really, really interested how to make this work so I raise this question again on a different thread as I consider previous answer is wrong, speculative or environment specific.
$ journalctl -u nginx
contains only lines like
Feb 08 13:05:23 Username systemd[1]: Started A high performance web server and a reverse proxy server.
and no sign of access logs :(
According to the nginx documentation, the error_logdirective supports stderras its argument. The following configuration should therefore log error messages to stderr: http { error_log stderr; ...
Configuring Logging 1 Setting Up the Error Log. NGINX writes information about encountered issues of different severity levels to the error log. ... 2 Setting Up the Access Log. ... 3 Enabling Conditional Logging. ... 4 Usecase: Sampling TLS Parameters. ... 5 Logging to Syslog. ... 6 Live Activity Monitoring. ...
By default, the NGINX image is configured to send NGINX access log and error log to the Docker log collector. This is done by linking them to stdout and stderr 1.
Therefore if NGINX is unable to start or abruptly stopped running then you should check the error logs to find more details. You may also find few warnings in the error log but it does not indicate that a problem has occurred but the event may pose a serious issue in the near future.
server {
error_log syslog:server=unix:/dev/log;
access_log syslog:server=unix:/dev/log;
...
}
Default journald configuration (I'm running Ubuntu 15.04) reads from syslog, so this config is all it takes to have logs be viewable with journalctl -u nginx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With