Skip to content

Traefik SSL Configuration

Traefik provides automatic SSL termination, security headers, and reverse proxying for SPEAR deployments. It supports both Let’s Encrypt certificates for production and self-signed certificates for testing/internal use.

┌─────────────────────────────────┐
│ Internet │
└─────────────┬───────────────────┘
┌─────────────▼───────────────────┐
│ Traefik (ports 80/443) │
│ - SSL termination │
│ - Security headers │
│ - Request routing │
└─────────────┬───────────────────┘
│ http://localhost:8090
┌─────────────▼───────────────────┐
│ SPEAR Backend │
│ - PocketBase auth │
│ - API endpoints │
│ - Static file serving │
└─────────────────────────────────┘

Install Traefik as part of the SPEAR deployment using the --with-traefik flag:

Terminal window
sudo ./scripts/build-and-deploy.sh \
--with-traefik \
--domain example.com \
--acme-email [email protected]

With Self-Signed Certificate (Testing/Internal)

Section titled “With Self-Signed Certificate (Testing/Internal)”
Terminal window
sudo ./scripts/build-and-deploy.sh \
--with-traefik \
--domain example.com \
--self-signed

This integrated approach:

  1. Builds and deploys the SPEAR application
  2. Downloads and installs Traefik binary
  3. Generates configuration for your domain
  4. Sets up SSL certificates
  5. Creates and starts systemd services

To install Traefik separately from SPEAR:

Terminal window
cd scripts/traefik
# With Let's Encrypt SSL
sudo ./install.sh --domain example.com --email [email protected]
# With self-signed certificate
sudo ./install.sh --domain example.com --self-signed
# Custom backend URL
sudo ./install.sh --domain example.com --email [email protected] --backend-url http://localhost:8080
OptionDescription
-d, --domain DOMAINDomain name for SSL certificate (required)
-e, --email EMAILEmail for Let’s Encrypt (required unless —self-signed)
-b, --backend-url URLBackend URL (default: http://localhost:8090)
-s, --self-signedUse self-signed certificate
-v, --version VERSIONTraefik version (default: latest)
--uninstallRemove Traefik installation
Terminal window
sudo ./install.sh --uninstall

After installation, Traefik files are located at:

PathDescription
/usr/local/bin/traefikTraefik binary
/etc/traefik/traefik.ymlStatic configuration
/etc/traefik/dynamic/Dynamic configuration files
/var/lib/traefik/acme/Let’s Encrypt certificates
/var/lib/traefik/certs/Self-signed certificates
/var/log/traefik/Log files
Terminal window
# Check status
sudo systemctl status traefik-spear
# View logs
sudo journalctl -u traefik-spear -f
# Restart
sudo systemctl restart traefik-spear
# Stop
sudo systemctl stop traefik-spear
# Start
sudo systemctl start traefik-spear

The static configuration (/etc/traefik/traefik.yml) defines:

  • Entry points (HTTP/HTTPS)
  • Let’s Encrypt or self-signed TLS
  • Logging settings
  • Metrics endpoints

Changes to static configuration require a service restart:

Terminal window
sudo systemctl restart traefik-spear

The dynamic configuration (/etc/traefik/dynamic/spear.yml) defines:

  • Routing rules for your domain
  • Backend service URL
  • Security headers and middleware
  • Large file upload support (500MB)

Changes to dynamic configuration are auto-loaded without restart.

  1. For dynamic config changes: Edit files in /etc/traefik/dynamic/ - changes are auto-loaded
  2. For static config changes: Edit /etc/traefik/traefik.yml and restart:
    Terminal window
    sudo systemctl restart traefik-spear

Traefik provides these security features out of the box:

FeatureDescription
HTTPS OnlyAll HTTP traffic redirects to HTTPS
HSTSHTTP Strict Transport Security enabled
Security HeadersXSS protection, frame options, content type sniffing prevention
CSPContent Security Policy configured for SPEAR
Auto RenewalLet’s Encrypt handles certificate renewal automatically

After successful deployment:

ServiceURL
SPEAR Applicationhttps://your-domain.com
Health Checkhttps://your-domain.com/api/health
LogLocation
Traefik main log/var/log/traefik/traefik.log
Access log/var/log/traefik/access.log
Systemd journaljournalctl -u traefik-spear
Terminal window
# Check ACME logs
sudo journalctl -u traefik-spear | grep -i acme
# Verify certificate file
ls -la /var/lib/traefik/acme/acme.json
# Reset certificates (force renewal)
sudo rm /var/lib/traefik/acme/acme.json
sudo systemctl restart traefik-spear
Terminal window
# Test backend directly
curl http://localhost:8090/api/health
# Check SPEAR service
sudo systemctl status spear
Terminal window
# Check what's using ports 80/443
sudo netstat -tlnp | grep -E ':80|:443'
# Or with ss
sudo ss -tlnp | grep -E ':80|:443'
Terminal window
# Verify DNS resolution
nslookup your-domain.com
dig your-domain.com
Terminal window
# Test SSL certificate
openssl s_client -connect your-domain.com:443 -servername your-domain.com
# Check certificate expiry
echo | openssl s_client -connect your-domain.com:443 2>/dev/null | openssl x509 -noout -dates

Run the validation script to check your installation:

Terminal window
cd scripts/traefik
./validate.sh

This checks:

  • Traefik binary installation
  • Configuration files
  • Service status
  • Port availability
  • Backend connectivity
Terminal window
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw enable
Terminal window
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload
Terminal window
# Stop Traefik
sudo systemctl stop traefik-spear
# Access backend directly on port 8090
curl http://localhost:8090/api/health
Terminal window
# For Let's Encrypt
sudo systemctl stop traefik-spear
sudo rm -f /var/lib/traefik/acme/acme.json
sudo systemctl start traefik-spear
# For self-signed
sudo systemctl stop traefik-spear
sudo rm -f /var/lib/traefik/certs/*.pem
# Re-run install.sh with --self-signed to regenerate
Terminal window
# Uninstall
sudo ./install.sh --uninstall
# Reinstall
sudo ./install.sh --domain your-domain.com --email [email protected]

To update Traefik to a newer version:

Terminal window
# Stop service
sudo systemctl stop traefik-spear
# Reinstall with new version
sudo ./install.sh --domain your-domain.com --email [email protected] --version v3.1.0
# Verify
traefik version

After deployment with Traefik:

ItemValue
Domainhttps://your-domain.com
Status Commandsudo systemctl status traefik-spear
Logs Commandsudo journalctl -u traefik-spear -f