goaccess icon indicating copy to clipboard operation
goaccess copied to clipboard

NGINX: Keep docker logs AND goaccess

Open iot-resister opened this issue 3 years ago • 1 comments

Hi,

First, goaccess is awesome!

But I'm a bit stuck. I've tried various things and this seems the most simple but also most hackish. I'm trying to keep my docker logs AND have it read by goaccess. The best solution is something like this on a cron job.

 cat $(docker inspect --format='{{.LogPath}}' test) | jq -r '.log|tostring'  >>  ~/goaccess/test/access.log 

Then your image can read -v "~/goaccess/test:/srv/logs"

Another solution is to modify the Dockerfile like so: storing docker ngnix access inside a volume

But in doing this I lose my docker logs, also the cron solution will work for all containers that have a parseable log.

Perhaps there is some linux-fu I can use to keep the symlink AND tee it into a file?

Please advise

iot-resister avatar Apr 01 '21 22:04 iot-resister

Hi! First step is to reconfigure your nginx.conf file:

server {
  listen 80 {
    access_log /var/log/nginx/access.log combined;
    access_log /var/log/nginx/goaccess.log combined;
    location * {
      ...
    }
  }
}

This config means that all logs, that nginx produced, will be written to two files: default access.log and custom goaccess.log

Next step is your Dockerfile/docker-compose file. I prefer docker-compose, so its here:

version: "3.8"

services:
  nginx:
    image: nginx
    volumes:
      - ./log/:/var/log/nginx/:rw

  goaccess:
    image: goaccess
    volumes:
      - ./log/:/any/folder/you/specified/:ro

It means that default /var/log/nginx/ directory will be mounted to folder /log in the same directory where your docker-compose file placed. Also you will mount this /log directory to any directory inside goaccess

sbulatnikov avatar May 17 '23 13:05 sbulatnikov