I have a machine behind a firewall that I would like to be accessible from the web. I have a VPS at example.com, and I would like traffic sent to device.example.com to reach my device behind the firewall.

I've managed to get the firewalled device accessible through example.com:2210 with the use of a reverse SSH tunnel. On the firewalled device, I ran ssh -R 2210:localhost:22 root@example.com.

Now, I would like HTTP traffic sent to device.example.com to be redirected to my firewalled device. I looked at using a SOCKS proxy, but nginx on example.com seems to be too high of a network layer for a SOCKS proxy. How can I redirect all HTTP traffic (or even all network traffic) to my firewalled device?


Because you need to look at the Host header in HTTP requests (unless you have multiple IP addresses, so subdomain.example.com can have a dedicated address), you need something that deals with HTTP. So nginx is definitely a good choice. You need to set it up as a so-called “reverse proxy”.

When the reverse proxy receives a request, it will be forwarded (internally) to the specified “upstream” service. The service’s response will then be returned to the client. The client doesn’t know anything about this.

Setting up a reverse proxy is super easy on both Apache and nginx.

  • What if I wanted to receive more than HTTP traffic? e.g. run an arbitrary service on port xxxx and be able to access it through device.example.com:xxxx – Ari Lotter Oct 6 '16 at 17:17
  • Few protocols have a concept of host names. So your service will also be available at example.com, because you’re probably using wildcard subdomains that all point to a single IP address. You could just open up your SSH reverse tunnel publicly. // Keep in mind though that the original remote address is lost this way. A more complicated setup with a VPN tunnel and port forwarding is probably better, but requires good network knowledge. – Daniel B Oct 6 '16 at 17:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.