←back to thread

319 points SpaghettiX | 1 comments | | HN request time: 0.2s | source
Show context
yewenjie ◴[] No.30289838[source]
How do I achieve the following related task with minimal effort?

I have a domain and VPS. I want to expose a local dev server running on my laptop to something like mydomain.xyz/something temporarily. I want to host it myself and would prefer open-source tools.

replies(3): >>30289988 #>>30290049 #>>30290331 #
lftl ◴[] No.30290331[source]
SSH into the VPS from the laptop with port-forwading:

ssh -R 8000:localhost:80 mydomain.xyz

Now you should be able to access your local laptop on port 8000 of the VPS. There are a few easy steps you can add if you want to make it a bit more ergonomic or permanent. If you don't want to use an alternate port, you can just forward the port on the VPS with iptables.

iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 8000

If you want the link to be more permanent, I'd suggest using wireguard instead of ssh. That's a little more effort, but not ridiculous.

replies(1): >>30295443 #
1. Jenda_ ◴[] No.30295443[source]
You can directly expose the port to the internet, not only localhost, with ssh:

- put "GatewayPorts clientspecified" into /etc/ssh/sshd_config, restart sshd

- ssh -R 0.0.0.0:8000:localhost:80 (the first parameter is the address where the tunnel should listen -- you can also pass something like 192.168.0.123 and expose it only to LAN etc.)

It's then reachable on your_vps:8000.

If you need it on the "correct" port and you are already running some other webserver (so you need to share that port), you need to set up a reverse proxy based on hostname or URL. I personally use haproxy, but for example nginx can do it too.