Configuration
The MekongTunnel server is configured entirely via environment variables. No config file required.
Setup
cp .env.example .env
nano .envVariables
| Variable | Default | Description |
|---|---|---|
DOMAIN | proxy.mekongtunnel.dev | Your domain — tunnels become subdomains of this |
SSH_ADDR | :22 | SSH server listen address |
HTTP_ADDR | :80 | HTTP redirect server address |
HTTPS_ADDR | :443 | HTTPS proxy server address |
STATS_ADDR | 127.0.0.1:9090 | Metrics endpoint (localhost only) |
MAX_TUNNELS_PER_IP | 1000 | Max concurrent tunnels per IP (v1.4.1+) |
MAX_TOTAL_TUNNELS | 0 | Max total active tunnels — 0 means unlimited (v1.4.7+) |
MAX_CONNECTIONS_PER_MINUTE | 0 | Max 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_SECOND | 0 | Per-tunnel HTTP rate limit — 0 disables the limiter |
BURST_SIZE | 0 | Per-tunnel burst allowance — 0 disables the limiter |
RATE_LIMIT_VIOLATIONS_MAX | 0 | Rate-limit violations before an IP is auto-blocked — 0 disables auto-blocking |
BLOCK_DURATION | 0 | How long an auto-block lasts (Go duration, e.g. 15m) — 0 disables blocking |
MAX_REQUEST_BODY_MB | 1024 | Max incoming request body in MB — 0 means unlimited |
MAX_RESPONSE_BODY_MB | 1024 | Max response body in MB — 0 means unlimited |
MAX_WEBSOCKET_TRANSFER_MB | 0 | Max MB per WebSocket direction — 0 means unlimited |
HOST_KEY_PATH | host_key | SSH host key file path (auto-generated if missing) |
TLS_CERT | /etc/letsencrypt/live/proxy.mekongtunnel.dev/fullchain.pem | TLS certificate path (docker-compose.yml sets /certs/fullchain.pem) |
TLS_KEY | /etc/letsencrypt/live/proxy.mekongtunnel.dev/privkey.pem | TLS private key path (docker-compose.yml sets /certs/privkey.pem) |
API_URL | derived 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.pemHard-coded limits
The following limits are compile-time constants (in internal/config/config.go). To change them, rebuild the binary:
| Constant | Value | Description |
|---|---|---|
DefaultTunnelLifetime | 24 hours | Lifetime when the client requests none |
ReservedDefaultTunnelLifetime | 7 days | CLI default when --subdomain is used |
MaxTunnelLifetime | 7 days | Max user-requested tunnel duration — the server rejects longer MEKONG_EXPIRE values |
| Idle timeout | same as the lifetime | A tunnel also closes after being idle for its lifetime (24 h by default) |
WebSocketIdleTimeout | 6 hours | WebSocket idle timeout |
SSHHandshakeTimeout | 30 seconds | SSH 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/mekongtunnelConnect to the dev instance via raw SSH:
ssh -t -R 80:localhost:5173 yourdomain.com -p 2223