【发布时间】:2015-04-08 06:23:56
【问题描述】:
我想将 nginx 访问日志重定向到 stdout 以便能够通过 journalctl (systemd) 对其进行分析。
有相同的问题与批准的答案。
Have nginx access_log and error_log log to STDOUT and STDERR of master process
但这对我不起作用。使用/dev/stderr,我得到open() "/dev/stderr" failed (6: No such device or address)。使用/dev/stdout,我在journalctl -u nginx 中没有访问日志。
nginx.conf
daemon off;
http {
access_log /dev/stdout;
error_log /dev/stdout;
...
}
...
网站名称.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
我已尽我所能通过更改上述代码中的每个可能参数并使用不同的 nginx 版本(1.2、1.6)来解决此问题,但没有任何成功。
我真的非常非常感兴趣如何完成这项工作,所以我在另一个线程上再次提出这个问题,因为我认为之前的答案是错误的、推测性的或特定于环境的。
$ journalctl -u nginx
只包含像
这样的行 Feb 08 13:05:23 Username systemd[1]: Started A high performance web server and a reverse proxy server.
并且没有访问日志的迹象:(
【问题讨论】:
标签: logging nginx stderr systemd