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

nginx 在 Traefik 后面运行的日志:

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"

谢谢

解决方法

默认情况下,traefik 不会在其访问日志中记录标头。你必须添加它们。查看文档的 this part

,

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

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

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...