NGINX Proxy Tunnel

Table of Contents

Description

This project allows you to access an application running on localhost from a remote URL.

This is useful for testing integrations that cannot access localhost and need an application running in the cloud.

If you've used ngrok, it works the same way, but with a little more control.

Diagram

Setup

1. Clone the repository on your instance

git clone https://github.com/GiovanniCavallari/nginx-proxy.git

2. Run the script

bash bin/run HOST_PORT TUNNEL_PORT TUNNEL_PATH CONTAINER_NAME

Params explained:

  • HOST_PORT is the port to receive browser requests on host.
  • TUNNEL_PORT is the port that will be used to redirect browser requests to localhost.
  • TUNNEL_PATH is the path you will access to redirect to your localhost.
  • CONTAINER_NAME is the container name to make docker cli easy to use.

3. Start the sample app on localhost

Start some sample app for the proxy tunnel to access your localhost and return the content. For example, some app using express.

4. Open SSH connection

ssh -nN -R TUNNEL_PORT:localhost:LOCALHOST_APP_PORT username@yourdomain.com

Ports explained:

  • TUNNEL_PORT is the forwarded port on the host that we use to directly SSH into the container.
  • LOCALHOST_APP_PORT refers to the port that your app is running on localhost.

5. Access the proxy tunnel URL

As long as you keep this SSH connection open, you'll be able to access your app from either:

Setup SSL

The SSL Certificate is generated by https://certbot.eff.org.

1. Run the script

bash bin/setup-ssl DOMAIN_NAME EMAIL CONTAINER

Params explained:

  • DOMAIN_NAME is the domain name to certbot validate and generate a SSL Certificate.
  • EMAIL is the email that CA will send notification emails to the address you provide if you do not renew certificates that are about to expire.
  • CONTAINER is the container name or container id.

2. Access the proxy tunnel URL

As long as you keep this SSH connection open, you'll be able to access your app from https://dev.app.com.

Setup rule

Run the script to create and setup a new rule on nginx:

bash bin/setup-rule RULE_NAME TUNNEL_PATH TUNNEL_PORT CONTAINER

Note: if a RULE_NAME that already exists is set, the old rule will be overwritten

Params explained:

  • RULE_NAME is the name used to create a file for the rule.
  • TUNNEL_PATH is the path you will access to redirect to your localhost.
  • TUNNEL_PORT is the port that will be used to redirect browser requests to localhost.
  • CONTAINER is the container name or container id.