Skip to content

Instantly share code, notes, and snippets.

@Kambaa
Last active April 26, 2025 21:38
Show Gist options
  • Save Kambaa/8b99f6636678a5848cf126459a4e9165 to your computer and use it in GitHub Desktop.
Save Kambaa/8b99f6636678a5848cf126459a4e9165 to your computer and use it in GitHub Desktop.

βš™οΈ server.toml example (in the same folder)

[server]
bind_addr = "0.0.0.0:2333"
default_token = "YOUR_SUPER_SECRET_TOKEN"

[server.services]
# Services are dynamically registered by clients

Docker compose

version: '3.8'

services:
  rathole-server:
    image: rapiz1/rathole:latest
    container_name: rathole-server
    restart: unless-stopped
    command:
      - rathole-server
      - -c
      - /etc/rathole/config.toml
    volumes:
      - ./server.toml:/etc/rathole/config.toml:ro
    ports:
      - "2333:2333"
      - "9000-9999:9000-9999"
    environment:
      - RUST_LOG=info
    deploy:
      resources:
        limits:
          memory: 50M
          cpus: '0.20'

πŸ‘Ύ client-template.toml (Template for client config)

[client]
server_addr = "frp.mydomain.com:2333"
default_token = "YOUR_SUPER_SECRET_TOKEN"
tls_name = "frp.mydomain.com"

[client.services]
[client.services.SERVICE_NAME]
local_addr = "127.0.0.1:PORT"

βœ… Will dynamically replace SERVICE_NAME and PORT via script. πŸ”₯ start-tunnel.sh (Simple bash script to start tunnels with random ID)

#!/bin/bash

if [ $# -lt 1 ]; then
  echo "Usage: $0 <local-port>"
  exit 1
fi

LOCAL_PORT=$1
RANDOM_ID=$(cat /dev/urandom | tr -dc 'a-z0-9' | fold -w 8 | head -n 1)

cp client-template.toml temp-client.toml

sed -i "s/SERVICE_NAME/${RANDOM_ID}/g" temp-client.toml
sed -i "s/PORT/${LOCAL_PORT}/g" temp-client.toml

echo "Starting tunnel..."
echo "Subdomain: ${RANDOM_ID}.frp.mydomain.com (needs NPM rule!)"
rathole-client -c temp-client.toml

βœ… Script generates:

A random tunnel ID

Creates a temp-client.toml

Runs rathole-client

Connects your app

πŸš€ Client Usage Example

Suppose you have an app on port 3000:

./start-tunnel.sh 3000

Terminal output:

Starting tunnel...
Subdomain: f93k2lsd.frp.mydomain.com (needs NPM mapping)

Done! Your app is now reachable at:

https://f93k2lsd.frp.mydomain.com

βœ… Ultra fast βœ… Super tiny RAM footprint βœ… Fully self-hosted βœ… Wildcard SSL via NPM

πŸ“ˆ Nginx Proxy Manager Setup:

βœ… Create a Wildcard SSL Cert for *.frp.mydomain.com βœ… Create a Wildcard Proxy Host:

Domain: *.frp.mydomain.com

Forward IP: your VPS IP or Docker IP

Forward Port: 9000-9999 range (dynamic)

Websockets: enabled βœ…

SSL: Force HTTPS βœ…

⚑ Final Summary Feature Status RAM Usage ~10MB server, ~5MB per client Subdomains Random, client-generated Authentication Secret token SSL NPM Wildcard Cert Ease of Use One-liner script πŸš€

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment