URI in logs only contains the path

1. The problem I’m having:

In our logs from the Caddy log directive, we seem to only be getting the path in the uri fields. There doesn’t seem to be any place in the logs where we can obtain the full uri (such as https://example.com/?query=string#fragment).

I’ve also explicitly tried appending various fields from the http.request module via the log_append directive such as orig_uri with no luck.

Is there a configuration problem with our server, or is this the intended behavior? Is there any other field we can use to access the full request uri?

Would appreciate any help or clarification!

2. Error messages and/or full log output:

Below is a sample log output from a localhost web request. However, we also have logs from our production server including non-localhost domains, so this is not exclusively a localhost issue.

The command issued to obtain this log was
curl "http://localhost/example?test=value#fragment".

I would therefore expect the uri field (or the custom full_uri field which refers to orig_uri) in the log to be http://localhost/example?test=value#fragment but it is instead /example?test=value#fragment.

{
  "level": "info",
  "ts": 1731530973.2146285,
  "logger": "http.log.access",
  "msg": "handled request",
  "request": {
    "remote_ip": "192.168.65.1",
    "remote_port": "61512",
    "client_ip": "192.168.65.1",
    "proto": "HTTP/1.1",
    "method": "GET",
    "host": "localhost",
    "uri": "/example?test=value",
    "headers": { "User-Agent": ["curl/8.7.1"], "Accept": ["*/*"] }
  },
  "bytes_read": 0,
  "user_id": "",
  "duration": 0.000083959,
  "size": 4,
  "status": 200,
  "resp_headers": {
    "Server": ["Caddy"],
    "Content-Type": ["text/plain; charset=utf-8"]
  },
  "scheme": "http",
  "full_uri": "/example?test=value"
}

3. Caddy version:

2.8.4

4. How I installed and ran Caddy:

a. System environment:

Both default Docker image and custom Docker build with xcaddy to include plugin.

c. Service/unit/compose file:

services:
  caddy:
    image: caddy:latest # or caddy:2.8.4
    volumes:
      - ./caddy/Caddyfile:/etc/caddy/Caddyfile
    ports:
      - 80:80
      - 443:443

d. My complete Caddy config:

:80 {
    respond "Hello!"
    log
    log_append full_uri {http.request.orig_uri}
}

The full URI would be wasteful: the scheme is already inferrable (presence of tls object), the host is in the host field, and the remainder of the URI is in the uri field.

The #fragment is not sent to the server so you will not see that in server logs.

2 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.