Documentation
v1
Config & Tools
Configuration

Configuration

The MekongTunnel server is configured entirely via environment variables. No config file required.

Setup

cp .env.example .env
nano .env

Variables

VariableDefaultDescription
DOMAINproxy.mekongtunnel.devYour domain — tunnels become subdomains of this
SSH_ADDR:22SSH server listen address
HTTP_ADDR:80HTTP redirect server address
HTTPS_ADDR:443HTTPS proxy server address
STATS_ADDR127.0.0.1:9090Metrics endpoint (localhost only)
MAX_TUNNELS_PER_IP1000Max concurrent tunnels per IP (v1.4.1+)
MAX_TOTAL_TUNNELS0Max total active tunnels — 0 means unlimited (v1.4.7+)
MAX_CONNECTIONS_PER_MINUTE0Max new SSH connections per IP per minute — 0 means unlimited (v1.4.7+)
MAX_ANON_TUNNELS_PER_IP(off)Max tunnels per IP opened without an account token — unset or 0 means no extra cap
REQUESTS_PER_SECOND0Per-tunnel HTTP rate limit — 0 disables the limiter
BURST_SIZE0Per-tunnel burst allowance — 0 disables the limiter
RATE_LIMIT_VIOLATIONS_MAX0Rate-limit violations before an IP is auto-blocked — 0 disables auto-blocking
BLOCK_DURATION0How long an auto-block lasts (Go duration, e.g. 15m) — 0 disables blocking
MAX_REQUEST_BODY_MB1024Max incoming request body in MB — 0 means unlimited
MAX_RESPONSE_BODY_MB1024Max response body in MB — 0 means unlimited
MAX_WEBSOCKET_TRANSFER_MB0Max MB per WebSocket direction — 0 means unlimited
HOST_KEY_PATHhost_keySSH host key file path (auto-generated if missing)
TLS_CERT/etc/letsencrypt/live/proxy.mekongtunnel.dev/fullchain.pemTLS certificate path (docker-compose.yml sets /certs/fullchain.pem)
TLS_KEY/etc/letsencrypt/live/proxy.mekongtunnel.dev/privkey.pemTLS private key path (docker-compose.yml sets /certs/privkey.pem)
API_URLderived from DOMAIN (proxy.example.com → https://api.example.com)API the tunnel server syncs tunnels with
TUNNEL_EDGE_SECRET(none)Shared secret for API ↔ tunnel server calls (also unlocks the stats port via X-Tunnel-Secret)
DATABASE_URL(none)Postgres URL for token validation; without it (and without API_URL + TUNNEL_EDGE_SECRET) users just get random subdomains

Example .env

# Domain — tunnels become subdomains of this
DOMAIN=yourdomain.com

# Server ports
SSH_ADDR=:22
HTTP_ADDR=:80
HTTPS_ADDR=:443
STATS_ADDR=127.0.0.1:9090

# Per-IP tunnel limit (default: 1000)
MAX_TUNNELS_PER_IP=1000

# Total tunnel limit — 0 means unlimited (default: 0)
MAX_TOTAL_TUNNELS=0

# Max new SSH connections per IP per minute — 0 means unlimited (default: 0)
MAX_CONNECTIONS_PER_MINUTE=0

# SSH host key (auto-generated on first run)
HOST_KEY_PATH=/host_key

# TLS certificates
TLS_CERT=/certs/fullchain.pem
TLS_KEY=/certs/privkey.pem

Hard-coded limits

The following limits are compile-time constants (in internal/config/config.go). To change them, rebuild the binary:

ConstantValueDescription
DefaultTunnelLifetime24 hoursLifetime when the client requests none
ReservedDefaultTunnelLifetime7 daysCLI default when --subdomain is used
MaxTunnelLifetime7 daysMax user-requested tunnel duration — the server rejects longer MEKONG_EXPIRE values
Idle timeoutsame as the lifetimeA tunnel also closes after being idle for its lifetime (24 h by default)
WebSocketIdleTimeout6 hoursWebSocket idle timeout
SSHHandshakeTimeout30 secondsSSH handshake timeout

Rate limits, auto-blocking and body-size limits above are runtime variables (see the table above) and are all off / unlimited by default, except the 1 GB request and response body caps.

Running multiple instances

# Production instance
DOMAIN=yourdomain.com ./bin/mekongtunnel
 
# Dev instance on alternate ports
SSH_ADDR=:2223 \
HTTP_ADDR=:8080 \
HTTPS_ADDR=:8443 \
STATS_ADDR=127.0.0.1:9091 \
DOMAIN=yourdomain.com \
./bin/mekongtunnel

Connect to the dev instance via raw SSH:

ssh -t -R 80:localhost:5173 yourdomain.com -p 2223