Score:0

How do I get lighttpd access log to stdout?

in flag

I am running lighttpd in a docker container on Ubuntu (as a service that must always be up in my traefik setup). My docker-compose.yml contains:

  lighttpd:
    image: sebp/lighttpd
    container_name: lighttpd
    restart: unless-stopped
    volumes:
      - /srv/docker/traefik/lighttpd/etc/lighttpd.conf:/etc/lighttpd/lighttpd.conf
      - /srv/docker/traefik/lighttpd/log/error.log:/var/log/lighttpd/error.log
      - /srv/docker/traefik/lighttpd/log/access.log:/var/log/lighttpd/access.log
      - /var/www/miniserver/html/:/var/www/html/
    ports:
      - "80"
    tty: true
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.lighttpd.rule=Host(`foo.rna.nl`)"
      - "traefik.http.routers.lighttpd.entrypoints=web"
      - "traefik.http.routers.lighttpd.tls=false"
    networks:
      - proxy

lighttpd works, serves me index.html, but:

# docker logs lighttpd
2022-10-29 12:13:55: (server.c.1568) server started (lighttpd/1.4.64)

I get the startup message, but nothing else. When I direct access log to a file, I get access log entries there:

172.26.0.2 foo.rna.nl - [29/Oct/2022:11:53:02 +0000] "GET /index.html HTTP/1.1" 200 37 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.0 Safari/605.1.15"

How do I direct lighttpd's access log to stdout? I tried both of these:

accesslog.filename = "/proc/self/fd/1"
accesslog.filename = "/dev/stdout"

My full lighttpd.conf:

server.modules = (
    "mod_indexfile",
    "mod_access",
    "mod_alias",
    "mod_redirect",
    "mod_accesslog",
)

server.document-root = "/var/www/html" 
#server.errorlog = "/var/log/lighttpd/error.log"
server.port = 80

mimetype.assign = (
  ".html" => "text/html", 
  ".txt" => "text/plain",
  ".jpg" => "image/jpeg",
  ".png" => "image/png" 
)

accesslog.filename = "/proc/self/fd/1"
#accesslog.filename = "/dev/stdout"
#accesslog.filename = "/var/log/lighttpd/access.log"
Score:1
pt flag

It looks like Lighttpd must close stdout when it start up, so you can't send output there, but you can send access logs to stderr:

accesslog.filename = "/dev/fd/2"

(Or /proc/self/fd/2 if you prefer.)

If you really want logs on stdout instead of stderr, you can perform some fd redirection tricks as shown here:

  1. Redirect a new fd to the original stdout:

    #!/bin/sh
    exec 3>&1
    lighttpd -D -f /etc/lighttpd/lighttpd.conf
    
  2. Point the access log at the new fd:

    accesslog.filename = "/dev/fd/3" 
    

This requires overriding the existing container startup command with a shell script.

gctwnl avatar
in flag
I tried using fd2 for `accesslog.filename` and that works, thanks. Redirection means I must change the default startup of the `lighttpd` container, maybe try that later because I don't know how to easily do that using `docker compose`.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.