HTTPS is now fully automatic at container startup! No manual steps required.
Windows:
start-https.batLinux/Mac:
bash start-https.shThat's it! Everything else happens automatically:
- ✅ Certificates generated (if needed)
- ✅ nginx configured
- ✅ Security settings enabled
- ✅ All services started with HTTPS
Two deployment modes:
docker-compose -f docker-compose.yml -f docker-compose.https-auto.yml up -dFlow:
1. certgen init container starts
├─ Checks if nginx/ssl/cert.pem exists
├─ If missing: generates self-signed certificate
│ ├─ Uses OpenSSL
│ ├─ Valid for 10 years
│ └─ Includes localhost + detected IP
└─ Exits successfully
2. nginx starts (depends on certgen completion)
├─ Uses certificates from nginx/ssl/
├─ Listens on ports 80 (redirect) and 443 (HTTPS)
└─ Proxies to app:8080
3. app starts with secure settings
├─ WTF_CSRF_SSL_STRICT=true
├─ SESSION_COOKIE_SECURE=true
└─ CSRF_COOKIE_SECURE=true
docker-compose -f docker-compose.yml -f docker-compose.https-mkcert.yml up -dFlow:
1. mkcert init container starts
├─ Has mkcert pre-installed
├─ Checks if nginx/ssl/cert.pem exists
├─ If missing:
│ ├─ Installs local CA
│ ├─ Generates trusted certificate
│ ├─ Copies rootCA.pem for host installation
│ └─ Valid for 10 years
└─ Exits successfully
2. nginx starts (same as Mode 1)
3. app starts (same as Mode 1)
| File | Purpose |
|---|---|
start-https.sh |
Automatic startup for Linux/Mac |
start-https.bat |
Automatic startup for Windows |
setup-https-mkcert.sh |
Manual mkcert setup (legacy) |
setup-https-mkcert.bat |
Manual mkcert setup (legacy) |
| File | Purpose |
|---|---|
docker-compose.https-auto.yml |
Self-signed certificates (automatic) |
docker-compose.https-mkcert.yml |
mkcert certificates (automatic) |
docker/Dockerfile.mkcert |
mkcert image builder |
| File | Purpose |
|---|---|
scripts/generate-certs.sh |
Self-signed cert generator |
docker/generate-mkcert-certs.sh |
mkcert cert generator |
| File | Purpose |
|---|---|
README_HTTPS_AUTO.md |
Automatic HTTPS guide |
README_HTTPS.md |
Manual HTTPS guide |
HTTPS_MKCERT_GUIDE.md |
Detailed mkcert documentation |
Using Docker's init container pattern for certificate generation:
services:
certgen:
image: alpine:latest
volumes:
- ./nginx/ssl:/certs
command: sh /scripts/generate-certs.sh
restart: "no" # Runs once
nginx:
depends_on:
certgen:
condition: service_completed_successfully # Waits for certgen
# ... rest of configBenefits:
- ✅ Idempotent (safe to run multiple times)
- ✅ No certificates needed in repo
- ✅ Auto-generates on first run
- ✅ Reuses existing certificates
- ✅ No manual intervention
Certificates stored in nginx/ssl/:
nginx/ssl/
├── cert.pem # Public certificate
├── key.pem # Private key
└── rootCA.pem # CA cert (mkcert only)
Lifecycle:
- First run: Generated by init container
- Subsequent runs: Reused (init container detects and skips)
- Persist across container restarts
- Valid for 10 years
Automatically applied via docker-compose:
app:
environment:
- WTF_CSRF_SSL_STRICT=true # Strict CSRF over HTTPS
- SESSION_COOKIE_SECURE=true # Cookies only over HTTPS
- CSRF_COOKIE_SECURE=true # CSRF cookies only over HTTPSAlso updates .env file:
# Automatically added/updated by start-https script
WTF_CSRF_SSL_STRICT=true
SESSION_COOKIE_SECURE=true
CSRF_COOKIE_SECURE=true| Feature | Self-Signed | mkcert |
|---|---|---|
| Setup | Zero config | One-time CA install |
| Browser Warning | Yes (safe to bypass) | No warnings ✅ |
| Encryption | Full TLS 1.2/1.3 | Full TLS 1.2/1.3 |
| Valid For | 10 years | 10 years |
| Trust | Only you | All browsers (after CA install) |
| Best For | Quick testing | Regular development |
| External Devices | Need CA install + bypass | Need CA install only |
User runs: start-https.sh/bat
│
↓
Detect local IP
│
↓
Create nginx config (if missing)
│
↓
Update .env with HTTPS settings
│
↓
Ask: Which certificate type?
│
┌────┴────┐
↓ ↓
Self-Signed mkcert
│ │
│ (Check if mkcert installed)
│ │
│ ┌────┴────┐
│ ↓ ↓
│ Found Not Found
│ │ │
│ │ Fall back to
│ │ self-signed
↓ ↓ ↓
docker-compose.https-auto.yml
│
↓
certgen/mkcert init container
│
↓
Generate certificates (if missing)
│
↓
nginx + app start with HTTPS
│
↓
Access: https://localhost
# Clone repo
git clone ...
cd TimeTracker
# Create config
cp env.example .env
# Start with HTTPS (automatic!)
bash start-https.sh
# Choose option 1 (self-signed)
# Access: https://localhost
# Click through browser warning once
# Done! ✅# Install mkcert once
brew install mkcert # or choco install mkcert
# Start with HTTPS
bash start-https.sh
# Choose option 2 (mkcert)
# Install CA: nginx/ssl/rootCA.pem (one-time)
# Restart browser
# Access: https://localhost
# No warnings ever! ✅# Use automatic HTTPS with mkcert
bash start-https.sh
# Option 2 (mkcert)
# All security settings: strict mode
# Test with real HTTPS behavior
# Perfect for pre-production testing ✅# Start with automatic HTTPS
bash start-https.sh
# Detects IP: 192.168.1.100
# Access from any device: https://192.168.1.100
# With mkcert: install CA once, no warnings
# With self-signed: bypass warning once per device
# All devices can access! ✅start-https.sh
↓
certgen checks: nginx/ssl/cert.pem missing
↓
Generates new certificate
↓
Saves to nginx/ssl/
↓
nginx uses new certificate
↓
App starts with HTTPS ✅start-https.sh
↓
certgen checks: nginx/ssl/cert.pem exists
↓
"Certificates already exist, skipping"
↓
Exits immediately
↓
nginx uses existing certificate
↓
App starts with HTTPS ✅# Delete certificates
rm -rf nginx/ssl/*
# Restart
bash start-https.sh
↓
certgen detects missing certificates
↓
Generates fresh certificates
↓
nginx uses new certificates ✅Check init container logs:
docker-compose logs certgen
# or
docker-compose logs mkcertVerify certificates exist:
ls -la nginx/ssl/
# Should show: cert.pem, key.pemCA not installed:
- Check
nginx/ssl/rootCA.pemexists - Install it (double-click on Windows/Mac)
- Restart browser completely
Wrong certificates:
# Regenerate
rm -rf nginx/ssl/*
bash start-https.shFind conflicting service:
# Windows
netstat -ano | findstr :443
# Linux/Mac
lsof -i :443Stop it or change nginx port
✅ Zero manual configuration ✅ One command to HTTPS ✅ Choice of certificate types ✅ Automatic security hardening ✅ Works with IP addresses ✅ No CSRF cookie issues
✅ Clean development experience ✅ Production-like HTTPS testing ✅ No certificate management ✅ Git-friendly (certs not committed) ✅ Reproducible across environments
✅ Idempotent deployment ✅ Container-native approach ✅ Minimal dependencies ✅ Self-contained solution ✅ Easy troubleshooting
This implementation also solves:
- CSRF Cookie Issues - Strict HTTPS mode fixes IP access problems
- Security Headers - Automatically applied
- Cookie Security - Secure flags enabled
- Mixed Content - All traffic over HTTPS
- WebSocket Support - Upgrade headers configured
AUTOMATIC_HTTPS_SUMMARY.md (this file)
│
├─ Quick Start
│ └─ README_HTTPS_AUTO.md
│
├─ Manual Setup (Legacy)
│ ├─ README_HTTPS.md
│ └─ HTTPS_MKCERT_GUIDE.md
│
├─ CSRF Issues
│ ├─ CSRF_IP_ACCESS_FIX.md
│ ├─ CSRF_IP_FIX_SUMMARY.md
│ └─ docs/CSRF_IP_ACCESS_GUIDE.md
│
└─ Advanced
└─ docs/HTTPS_SETUP_GUIDE.md
Fully Automatic HTTPS System:
- 🚀 One-command startup
- 🔐 Auto-generated certificates
- 🔧 Self-configuring nginx
- ⚙️ Auto-hardened security settings
- 🔄 Persistent across restarts
- 📱 Works with any device
- ✅ Zero manual intervention
# Start everything with HTTPS (automatic!)
bash start-https.sh # Linux/Mac
start-https.bat # Windows
# Access securely
https://localhost
https://192.168.1.100
# View logs
docker-compose logs -f
# Stop
docker-compose downBefore:
- ❌ Manual certificate generation required
- ❌ Complex nginx configuration
- ❌ Manual security settings
- ❌ CSRF issues with IP addresses
- ❌ Multiple scripts to run
After:
- ✅ One command:
bash start-https.sh - ✅ Everything automatic
- ✅ HTTPS just works
- ✅ No CSRF issues
- ✅ Production-ready security
Implementation Complete! 🎊
Enjoy your automatic HTTPS TimeTracker! 🔒🚀