首页 > 解决方案 > Traefik 的 access.log 中缺少用户代理

问题描述

我已将 Traefik 2.3.1 配置为将访问日志写入文件。但日志缺少用户代理(浏览器、操作系统信息)。

它以某种方式可配置吗?

Traefik 从 docker-compose.yml 运行:

version: '3.4'

services:
  proxy:
    image: traefik:2.3.1 
    command:
      - "--providers.docker=true"
    volumes:
      - "/var/run/docker.sock:/var/run/docker.sock:ro"
      - ./traefik/traefik.toml:/traefik.toml:ro
      - ./logs/traefik:/logs/traefik
    ports:
      - "80:80" 
      - "443:443"
    restart: unless-stopped

traefik.toml 中的一些行:

[accessLog]
  filePath = "/logs/traefik/access.log"
  bufferingSize = 100 

日志如下所示:

3.22.235.211 - - [01/Feb/2021:15:42:41 +0000] "GET /.env HTTP/1.1" 404 555 "-" "-" 367 "site@docker" "http://172.18.0.4:8000" 1ms
3.22.235.211 - - [01/Feb/2021:15:42:42 +0000] "POST / HTTP/1.1" 405 559 "-" "-" 368 "site@docker" "http://172.18.0.4:8000" 0ms
66.249.66.153 - - [01/Feb/2021:15:45:43 +0000] "GET /robots.txt HTTP/1.1" 200 13 "-" "-" 369 "site@docker" "http://172.18.0.4:8000" 1ms
66.249.66.153 - - [01/Feb/2021:15:45:44 +0000] "GET / HTTP/1.1" 200 11698 "-" "-" 370 "site@docker" "http://172.18.0.4:8000" 0ms

Traefik 后面运行 nginx 的日志:

172.18.0.2 - - [01/Feb/2021:15:42:41 +0000] "GET /.env HTTP/1.1" 404 555 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.129 Safari/537.36" "3.22.235.211"
172.18.0.2 - - [01/Feb/2021:15:42:42 +0000] "POST / HTTP/1.1" 405 559 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.129 Safari/537.36" "3.22.235.211"
172.18.0.2 - - [01/Feb/2021:15:45:43 +0000] "GET /robots.txt HTTP/1.1" 200 13 "-" "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)" "66.249.66.153"
172.18.0.2 - - [01/Feb/2021:15:45:44 +0000] "GET / HTTP/1.1" 200 11698 "-" "Mozilla/5.0 (Linux; Android 6.0.1; Nexus 5X Build/MMB29P) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.113 Mobile Safari/537.36 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)" "66.249.66.153"

谢谢

标签: user-agenttraefikaccess-log

解决方案


我改变了traefik.toml作为 tetram 指出,它开始工作:

[accessLog]
  filePath = "/logs/traefik/access.log"
  bufferingSize = 100  
  [accessLog.fields.headers.names]
    "User-Agent" = "keep"

推荐阅读