skip to Main Content

I have configured Traefik 2.3.1 to write an accesslog to a file. But the log is missing User Agent (browser, OS info).

Is it somehow configurable?

The Traefik is running from 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

Some lines from the traefik.toml:

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

And the log looks like this:

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

The log of nginx running behind the 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"

Thanks

2

Answers


  1. Chosen as BEST ANSWER

    I changed traefik.toml as tetram pointed and it started to work:

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

  2. By default traefik does not log headers in its access logs. You have to add them. Look at this part of the documentation.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search