Set up Caddy reverse proxy for domain access
If you want to access your trading bots through a domain name instead of localhost:8101
, you can set up Caddy as a reverse proxy.
# Caddyfile
your-trading-domain.com {
reverse_proxy localhost:8101
}
# Caddyfile for multiple trading strategies
bot1.your-domain.com {
reverse_proxy localhost:8101
}
bot2.your-domain.com {
reverse_proxy localhost:8102
}
bot3.your-domain.com {
reverse_proxy localhost:8103
}
trading.your-domain.com {
# Enable HTTPS automatically
tls your-email@example.com
# Optional: IP whitelist for additional security
@allowed {
remote_ip 192.168.1.0/24 203.0.113.0/24
}
handle @allowed {
reverse_proxy localhost:8101 {
# Headers for proper WebSocket support
header_up Host {host}
header_up X-Real-IP {remote_host}
header_up X-Forwarded-For {remote_host}
header_up X-Forwarded-Proto {scheme}
}
}
# Deny other IPs
handle {
respond "Access denied" 403
}
}
If you prefer subdirectories instead of subdomains:
your-domain.com {
# Main site content
handle / {
respond "Main site"
}
# Trading bot at /trading
handle /trading/* {
uri strip_prefix /trading
reverse_proxy localhost:8101
}
# Additional bots
handle /bot2/* {
uri strip_prefix /bot2
reverse_proxy localhost:8102
}
}
# Ubuntu/Debian
sudo apt install -y debian-keyring debian-archive-keyring apt-transport-https
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | sudo gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | sudo tee /etc/apt/sources.list.d/caddy-stable.list
sudo apt update
sudo apt install caddy
# macOS
brew install caddy
# Create Caddyfile in your project directory
nano Caddyfile
# Test configuration
caddy validate
# Run Caddy (foreground)
caddy run
# Or run as service (background)
sudo systemctl enable --now caddy
Caddy automatically handles HTTPS certificates via Let’s Encrypt:
trading.your-domain.com {
# HTTPS is automatic - no additional config needed
reverse_proxy localhost:8101
}
trading.your-domain.com {
# Method 1: IP-based restrictions
@allowed remote_ip 192.168.1.100 203.0.113.50
handle @allowed {
reverse_proxy localhost:8101
}
respond "Unauthorized" 401
}
trading.your-domain.com {
# Limit requests per IP
rate_limit {
zone static_ip_10pm {
key {remote_host}
events 10
window 1m
}
}
reverse_proxy localhost:8101
}
dig your-domain.com
# Check certificate status
caddy list-certificates
# Force certificate renewal
sudo systemctl stop caddy
sudo caddy run --config Caddyfile
docker ps | grep freqtrade
docker port freqtrade-YourStrategy
curl localhost:8101/api/v1/ping
If you change the default web ports in your bot configuration, update the Caddyfile accordingly:
# If bot uses port 8150 instead of 8101
trading.your-domain.com {
reverse_proxy localhost:8150
}
You can reference the proxy in your environment setup:
# .env file
WEB_DOMAIN=trading.your-domain.com
WEB_PORT=8101 # Still use localhost port for bot
Your bots will still bind to localhost ports, but be accessible via your domain:
# Launch bot normally
./docker-launch.sh NFI
# Access via domain (configured in Caddy)
# https://trading.your-domain.com
# Or direct access (still works)
# http://localhost:8101