[英]Nginx log to stderr
I want to redirect nginx access logs to stdout
to be able to analyze them through journalctl
(systemd). 我想将nginx访问日志重定向到
stdout
,以便能够通过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.
将nginx access_log和error_log日志记录到主进程的STDOUT和STDERR但它对我不起作用。 With
/dev/stderr
I get open() "/dev/stderr" failed (6: No such device or address)
. 使用
/dev/stderr
我得到open() "/dev/stderr" failed (6: No such device or address)
。 With /dev/stdout
I get no access logs in journalctl -u nginx
. 使用
/dev/stdout
我在journalctl -u nginx
没有访问日志。
nginx.conf nginx.conf
daemon off;
http {
access_log /dev/stdout;
error_log /dev/stdout;
...
}
...
sitename.conf 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 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. 我已经尽力通过改变上面代码中的每个可能参数并使用不同的nginx版本(1.2,1.6)来解决这个问题,但没有任何成功。
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 :( 并没有访问日志的迹象:(
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
默认的日志配置(我正在运行Ubuntu 15.04)从syslog中读取,所以这个配置只需要使用
journalctl -u nginx
查看日志
According to the nginx documentation , the error_log
directive supports stderr
as its argument. 根据nginx文档 ,
error_log
指令支持stderr
作为其参数。 The following configuration should therefore log error messages to stderr: 因此,以下配置应将错误消息记录到stderr:
http {
error_log stderr;
...
}
Unfortunately, access_log
doesn't support stdout
as its argument. 不幸的是,
access_log
不支持stdout
作为其参数。 However, it should be possible to set it to syslog
( documentation ) and get systemd to include syslog calls into its journal. 但是,应该可以将其设置为
syslog
( 文档 )并让systemd将syslog调用包含在其日志中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.