我尝试将以下内容添加到my_proxy.conf文件中,该文件已按https://github.com/jwilder/nginx-proxy#custom-nginx-configuration中所述安装到容器中的/etc/nginx/conf.d/中,但日志未写入logstash。

最初,我将此添加到conf文件中:

http {
  # Custom log format that also includes the host that processed the request
  log_format logstash '$remote_addr - $remote_user [$time_local] "$host" '
                  '"$request" $status $body_bytes_sent '
                  '"$http_referer" "$http_user_agent"';

  # Send logs to Logstash
  access_log syslog:server=logstash:5140,tag=nginx_access logstash;
  error_log syslog:server=logstash:5140,tag=nginx_error notice;
}

但是当我启动容器时,它告诉我"http" directive is not allowed here in /etc/nginx/conf.d/my_proxy.conf:11
所以现在我有
# Custom log format that also includes the host that processed the request
log_format logstash '$remote_addr - $remote_user [$time_local] "$host" '
                  '"$request" $status $body_bytes_sent '
                  '"$http_referer" "$http_user_agent"';

# Send logs to Logstash
access_log syslog:server=logstash:5140,tag=nginx_access logstash;
error_log syslog:server=logstash:5140,tag=nginx_error notice;

启动nginx时不会有任何抱怨,但也不会在logstash中添加任何内容。从这里我不知道如何解决。

最佳答案

Syslog不在容器中运行,因此将其用于日志记录没有意义。您的选择:

1.)在Docker守护程序级别配置gelf日志记录驱动程序:



Doc:https://docs.docker.com/config/containers/logging/configure/

2.)启动/配置专用的日志记录容器,该容器会将选定容器的数据发送到logstash。请参阅Logspout或其他类似工具。

工具:https://github.com/gliderlabs/logspout

关于docker - 如何将日志从jwilder/nginx-proxy docker镜像发送到logstash?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/55501393/

10-16 16:52