user-agent - 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"
谢谢
解决方案
我改变了traefik.toml作为 tetram 指出,它开始工作:
[accessLog]
filePath = "/logs/traefik/access.log"
bufferingSize = 100
[accessLog.fields.headers.names]
"User-Agent" = "keep"
推荐阅读
- jestjs - 如何测试函数内部的函数是否使用正确的参数调用
- c# - 服务器在 AngularJS 中响应状态为 500(内部服务器错误)
- c++ - 这算作递归吗?
- laravel - Laravel Eloquent:来自一个主键的多个外键
- r - 在 R 中创建范围条形图
- .net-core - DynamoDB 如何使用 .net 核心获取分区键的项目数?
- docker - 在 docker 中启用网络管理器
- angular - 三个 JS + Angular 7 导入控制器后出现错误 BufferAttribute
- javascript - 如何用打字稿继承本机反应组件?
- php - Laravel 控制器传递 HTML 元素?