TL;DR
You need to reach a service behind a reverse proxy or NAT (Network Address Translation). This guide covers common techniques like port forwarding, SSH tunneling, and using tools like ngrok. It assumes you have some level of access to the network or the machine hosting the service.
1. Understand the Problem
A reverse proxy sits in front of your target service, hiding its internal IP address and port. NAT does something similar on a home router. You can’t directly connect to the service; you must go through the proxy/router.
2. Port Forwarding (Home Router)
- Access your router’s configuration page: Usually found at
192.168.1.1or192.168.0.1in a web browser. You’ll need the admin username and password (often on a sticker on the router). - Find the Port Forwarding section: This might be called “Virtual Servers”, “NAT/PAT”, or similar.
- Create a new rule:
- Service Name: Give it a descriptive name (e.g., “MyWebApp”).
- Protocol: TCP, UDP, or Both (usually TCP for web services).
- External Port: The port you want to access from the outside world (e.g., 8080).
- Internal Port: The port your service is listening on (e.g., 3000).
- Internal IP Address: The local IP address of the machine running the service (e.g.,
192.168.1.100). Find this usingipconfig(Windows) orifconfig(Linux/macOS).
- Save and test: Access your public IP address followed by the external port in a web browser (e.g.,
http://your_public_ip:8080). You can find your public IP at whatismyip.com.
3. SSH Tunneling
If you have SSH access to a machine inside the network, you can create an SSH tunnel.
- Open a terminal: On your local machine.
- Create the tunnel: Use the following command:
ssh -L local_port:target_ip:target_port user@ssh_server_ip- local_port: The port on your local machine you’ll use to access the service (e.g., 8080).
- target_ip: The internal IP address of the target service (e.g.,
192.168.1.100). - target_port: The port your service is listening on (e.g., 3000).
- user@ssh_server_ip: Your SSH username and the IP address of the server you’re connecting to.
- Access the service: Access
localhost:local_portin your browser (e.g.,http://localhost:8080).
4. Using ngrok
ngrok creates a secure tunnel to your local machine, bypassing firewalls and NAT.
- Download and install ngrok: From ngrok.com.
- Run ngrok: Open a terminal and run:
ngrok http target_port- target_port: The port your service is listening on (e.g., 3000).
- Access the service: ngrok will provide a public URL in the terminal. Use this URL to access your service.
5. Reverse Proxy Configuration (If you control the proxy)
If you have administrative access to the reverse proxy itself, you can modify its configuration.
- Locate the configuration file: This varies depending on the proxy software (e.g., Nginx, Apache).
- Add a new upstream block: Configure the proxy to forward requests to your target service.
upstream my_app { server target_ip:target_port; }- target_ip: The internal IP address of the target service.
- target_port: The port your service is listening on.
- Add a new server block: Configure the proxy to listen for requests and forward them to the upstream.
server { listen 80; server_name example.com; location / { proxy_pass http://my_app; } } - Reload the proxy configuration: This varies depending on the software (e.g.,
nginx -s reload).