- Python 85%
- Shell 15%
Example of what the gateway web interface looks like:
setup #
on debian, install dependencies: sudo apt-get install rsync nginx-full python3 python3.11-venv
download code (rest of readme assume /srv/tunnel-gateway-server as working directory):
git clone https://codeberg.org/notplants/tunnel-gateway-server.git /srv/tunnel-gateway-server
create a python virtualenv for the python app
cd /srv/tunnel-gateway-server
python3 -m venv venv
and run pip install -r req.txt
add tunnel-gateway.service to systemd, enable it, and start it
cp tunnel-gateway.service /etc/systemd/system/tunnel-gateway.service
sudo systemctl daemon-reload
sudo systemctl enable tunnel-gateway.service
sudo systemctl start tunnel-gateway.service
add nginx.config and enable it:
cp tunnel-gateway-admin-nginx.conf /etc/nginx/sites-available/tunnel-gateway-server
sudo ln -s /etc/nginx/sites-available/tunnel-gateway-server /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx
for ssl to work, need to add certbot also to this server to create a cert for the admin interface
sudo apt install certbot python3-certbot-nginx -y
sudo certbot --nginx -d gateway-test.commoninternet.net
install tailscale and connect to relevant tailscale network
curl -fsSL https://tailscale.com/install.sh | sh && sudo tailscale up --auth-key=<redacted>
copy over nginx.conf to /etc/nginx.conf
cp nginx.conf /etc/nginx.conf
TODO: best way to substitute in here correct name for gateway admin interface
set up basicauth password
sudo apt-get install apache2-utils
sudo htpasswd -c /srv/tunnel-gateway-server/.htpasswd admin
gateway-server is now running
regex and wildcard entries #
The domain field in the web admin interface also accepts nginx map regex patterns prefixed with ~:
~^(.+\.)?example\.com$ 10.0.0.1
As a convenience, you can also use a wildcard domain, which creates a regex like above in the backend:
*.example.com 10.0.0.1
custom backend port (remapping 443) #
By default every domain is streamed to its backend on port 443. To route a
domain to a backend listening on a different port (e.g. 8443 instead of 443),
append :port to the IP/target value in the web admin interface:
example.com 10.0.0.1:8443
The full ip:port value is stored in tunnel_map.conf. In nginx.conf a regex
on the backend value appends :443 only when no port is present, so existing
entries (plain IP) keep using 443 and require no migration. Submitting a plain
IP (or ip:443) overwrites any previous port, and deleting a domain (IP 0)
removes the entry as usual.
tests #
pip install pytest && python3 -m pytest test_app.py