Ghost, GoAccess and docker compose

Example of use goaccess to read caddy access.log files.  

Setup an A Record to for blog.mydomain.org  and analytics.mydomain.org to point to your IP address for the server.  If on a local machine make sure your route 443 on your local router to your machine.

Setup local directories

mkdir docker
cd docker
mkdir -p data/caddy
mkdir -p data/caddylog
mkdir -p data/ghost/content
mkdir -p data/goaccess/data
mkdir -p data/goaccess/html

located in the docker directory docker-compose.yml don't forget to change the domain name for the url for Ghost!

version: "3.9"

x-logging:
  &default-logging
  options:
    max-size: '500m'
  driver: json-file

networks:
  web:
    external: true
  caddy_internal:
    external: false
    driver: bridge

services:
  caddy:
    image: caddy:latest
    restart: unless-stopped
    container_name: caddy
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - ./data/caddy/Caddyfile:/etc/caddy/Caddyfile
      - ./data/caddy/data:/data # Optional
      - ./data/caddy/config:/config # Optional
      - ./data/caddylog:/var/log/caddy
      - ./data/goaccess/html:/site/goaccess
    networks:
      - web
      - caddy_internal
  ghost:
    image: ghost:latest
    container_name: ghost
    hostname: ghost
    volumes:
      - ./data/ghost/content:/var/lib/ghost/content
    environment: # this section can be commented to start in dev mode by default
      url: https://blog.mydomain.org
      database__client: mysql
      database__connection__host: ghost_db
      database__connection__user: ghost
      database__connection__password: <changeme>
      database__connection__database: ghost
    depends_on:
      - ghost_db
    networks:
      - caddy_internal
    restart: unless-stopped
  goaccess:
    image: allinurl/goaccess
    container_name: goaccess
    hostname: goaccess
    restart: unless-stopped
    volumes:
      - "./data/goaccess/data:/srv/data"
      - "./data/goaccess/html:/srv/html"
      - "./data/caddylog:/srv/logs"
    networks:
      - caddy_internal
    command: /srv/logs/access.log -o /srv/html/index.html --log-format=CADDY

You need a password for analytics site.  To create a hash for basic auth.

$ caddy hash-password
Enter password:
Confirm password:
$2a$14$2yCs9UE3my0lueM1WxpgXO/uDHRjhqTQe7GZtSGKUzaRXY.ipcQt2

Next create ./docker/data/caddy/Caddyfile

Don't forget to use a real email, and change the password and the domain names for your machine.

{
	email me@myemail.com
}
(caddy-common) {
	encode gzip
	header {
	    -Server
	    Strict-Transport-Security "max-age=31536000; include-subdomains;"
	    X-XSS-Protection "1; mode=block"
	    X-Frame-Options "DENY"
	    X-Content-Type-Options nosniff
	    Referrer-Policy  no-referrer-when-downgrade
	    X-Robots-Tag "none"
       }
}
(logging) {
	log {
	
		output file /var/log/caddy/access.log
	}
}
blog.mydomain.org {
	import logging
	reverse_proxy ghost:2368
}
analytics.mydomain.org {
	basicauth / {
		admin $2a$14$2yCs9UE3my0lueM1WxpgXO/uDHRjhqTQe7GZtSGKUzaRXY.ipcQt2
	}
 	root * /site/goaccess
	file_server
}

Fire it up, check logs to make sure everything worked!  Go to https://blog.mydomain.org/ghost to create your admin user and create a post.  You can see the goaccess analytics on https://analytics.mydomain.org/