Secure Live Log Streaming

Interactive documentation for your project's logging system.

Purpose

This system provides a secure, read-only, live-streaming log dashboard for staging and production environments, eliminating the need for developer SSH access. This solution is lightweight and ideal for environments with minimal server resources.

Key Features

  • Secure Access: Password-protected dashboard using Nginx.
  • Real-Time Logs: Live-streams logs using Dozzle (not static files).
  • Lightweight: Minimal resource usage with Alpine Linux and Dozzle.
  • No SSH Needed: Completely eliminates the need for developer server access.
  • Environment Separation: Safely view staging and production logs separately.

System Architecture

Developer

Accesses via Port 1010

Nginx

Password Auth

Dozzle UI

Internal Port 8888

log-streamer-staging

Reads staging files

log-streamer-prod

Reads production files

Technologies Used

Docker
Nginx
Dozzle
Alpine Linux

Component Configuration

Here's what each part does, explained simply.

1. Nginx (Gateway)

Analogy: Think of this as the secure front-desk receptionist for our system.

Its job is to be the only "door" to the outside world. It stops everyone and asks for a password. If you have the right password, it connects you to the log dashboard.

Show Technical Details
  • Role: Securely reverse-proxies requests to Dozzle.
  • Listens: 1010
  • Config File: /etc/nginx/sites-available/log-viewer
  • Password File: /etc/nginx/.htpasswd

Nginx Configuration:

nginx.conf
server {
    # ... (config as before) ...
    listen 1010;
    server_name _;

    auth_basic "Restricted Access - Logs";
    auth_basic_user_file /etc/nginx/.htpasswd;

    location / {
        proxy_pass http://127.0.0.1:8888;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
    }
}

2. Dozzle (Dashboard)

Analogy: This is the live TV monitor that displays all the log streams.

This is the actual web page you see after you log in. It's a clean dashboard that shows all the developer messages (logs) as they happen, just like a live news feed.

Show Technical Details
  • Role: Provides the web UI.
  • Container Name: dozzle
  • Internal Port: 127.0.0.1:8888

Dozzle Docker Run Command:

bash
docker run -d --name dozzle \
  --volume=/var/run/docker.sock:/var/run/docker.sock \
  -p 127.0.0.1:8888:8080 \
  --restart=always \
  amir20/dozzle:latest

3. Log Streamers

Analogy: These are the translators that find text files and put them on the "live TV".

The "live TV" (Dozzle) can't read files. It only watches live feeds. These tiny programs find the log files, read them, and "broadcast" them as a live feed. We use two (Staging & Prod) so we never get the feeds mixed up.

Show Technical Details
  • Role: Reads log files from volumes and streams them as container output.
  • Container Names: log-streamer-staging, log-streamer-prod

Staging Streamer Command:

bash
docker run -d --name log-streamer-staging \
  --restart=always \
  --volume="/path/to/your-staging/storage_logs:/logs/laravel:ro" \
  --volume="/path/to/your-staging/nginx_logs:/logs/nginx:ro" \
  alpine \
  tail -F /logs/laravel/laravel.log /logs/nginx/access.log /logs/nginx/error.log

Production Streamer Command:

bash
docker run -d --name log-streamer-prod \
  --restart=always \
  --volume="/path/to/your-production/storage_logs:/logs/laravel:ro" \
  --volume="/path/to/your-production/nginx_logs:/logs/nginx:ro" \
  alpine \
  tail -F /logs/laravel/laravel.log /logs/nginx/access.log /logs/nginx/error.log

Maintenance & Troubleshooting

Quick commands for operating and maintaining the log system.

Check Status

Check all running Docker containers (you should see `dozzle`, `log-streamer-staging`, and `log-streamer-prod` listed as "Up").

bash
docker ps

Check the Nginx service status.

bash
sudo systemctl status nginx
Restart Components

Restart Nginx after a configuration change (tests config first).

bash
sudo nginx -t && sudo systemctl restart nginx

Restart individual Docker containers.

bash
docker restart dozzle
docker restart log-streamer-staging
docker restart log-streamer-prod
Update Password

To change the password for an existing `developer` user:

bash
sudo htpasswd /etc/nginx/.htpasswd developer

To add a new user (e.g., `new_dev`):

bash
sudo htpasswd /etc/nginx/.htpasswd new_dev