Skip to content

Instantly share code, notes, and snippets.

@kirpachov
Created September 30, 2022 07:53
Show Gist options
  • Save kirpachov/729769f8a6023525a313495524cf3a22 to your computer and use it in GitHub Desktop.
Save kirpachov/729769f8a6023525a313495524cf3a22 to your computer and use it in GitHub Desktop.

Tunneling http with caddy

You can expose a http port from a private network using caddy and ssh

Getting started

  1. Set up the server
  2. Set up the client
  3. Navigate to your host.

Server

Server must be a pc or a server with a static public ip and a nameserver. In my case, it's gonna be kirpachov.com.

# Step 1
git clone https://github.com/anderspitman/SirTunnel.git

# Step 2
# In this step you will be asked the password, this is necessary to enable caddy to bind low ports
# as low ports such as 80 require root permissions
cd SirTunnel; ./install.sh

# Step 3 - run the server
# Note that 'run' action will block the console; If you want a background process, use 'start' instead.
./caddy run --config caddy_config.json

At this point, your server should be set up.

Client

Client can by either your pc or another server. You can expose any port. In my case I'm just gonna expose port 80.

# After the server setup
ssh -tR 9001:localhost:80 kirpachov.com /home/sasha/SirTunnel/sirtunnel.py kirpachov.com 9001

9001 is the port where the tunnel will be created. The path of the sirtunnel.py file must be relative to the server. The last kirpachov.com can be replaced with anything such as cloud.kirpachov.com. WARNING: caddy server will auto-find ssl certificates and force https. It it will not find any certificate you may have issues.

Useful links

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