fravelgue
fravelgue

Reputation: 2883

Ngrok configure multiple port in same domain

Is it possible to open multiples ports in ngrok in same domain?

Something like:

Fowarding http://example.ngrok.com:50001 -> 127.0.0.1:50001

Fowarding http://example.ngrok.com:50002 -> 127.0.0.1:50002

I´m working in windows and it'll be useful for debuging with IIS Express

Upvotes: 145

Views: 171351

Answers (10)

Jay Patel
Jay Patel

Reputation: 306

The following code snippet works with the latest Ngrok version 3.

version: "3"
tunnels:
    first:
        addr: 4000
        proto: http
    second:
        addr: 5000
        proto: http
agent:
    authtoken: your_private_token

Upvotes: 0

robe007
robe007

Reputation: 3947

Yes, it is possible using multiple simultaneous tunnels, within the same hostname !

All you need to do, is to declare them on your configuration file, like this:

authtoken: 4nq9771bPxe8ctg7LKr_2ClH7Y15Zqe4bWLWF9p
tunnels:
  first-app:
    addr: 50001
    proto: http
    hostname: example.ngrok.com
    host_header: first-app.example.ngrok.com
  second-app:
    addr: 50002
    proto: http
    hostname: example.ngrok.com
    host_header: second-app.example.ngrok.com        

And run them with:

ngrok start --all

Look on the documentation for options, like hostname, subdomain, authtoken and host_header. Hope this help you !

P.S For Free plan remove custom host and header part like this it will be different domains FYI.

authtoken: 6yMXA63qefMZqCWSCHaaYq_5LufcciP1rG4LCZETjC6V
tunnels:
  first:
    addr: 3002
    proto: http    
  second:
    addr: 8080
    proto: http

NOTES:

Update: Nov 2024

for version 3, you need to do the following:

version: "3"
agent:
    authtoken: 2pNn6oWWEWEsdasc7xveBp2Q1TaPpl_3Jut8L2p4wCsdfEEF9BEcUk
      
tunnels:
  score_api:
    proto: http
    addr: 8000
  weather_api:
    proto: http
    addr: 9801

Upvotes: 162

Qui-Gon Jinn
Qui-Gon Jinn

Reputation: 4408

You would need to have a paid account to expose more than one port from the same machine using NGROK.

Edit Ngrok configuration file ngrok.yml

Use this syntax:

version: 3
agent:
  authtoken: 4nq9771bPxe8ctg7LKr_2ClH7Y15Zqe4bWLWF9p
endpoints:
  - name: foo
    description: foo123
    metadata: foo123
    url: foo.ngrok.io
    upstream:
      url: 8080
      protocol: http1
  - name: bar
    url: bar.ngrok.io
    upstream:
      url: 8080

Then run this command to check for errors:

ngrok config check

and this command to start all tunnels or endpoints that are defined in your Ngrok configuration file

ngrok start --all   

Upvotes: 1

Stefan Popovski
Stefan Popovski

Reputation: 516

I'm using a free plan

If you want to run multiple domains on https, this worked for me

ngrok config edit
version: "2"
authtoken: --your-ngrok-auth-token--
tunnels:
  api1:
    addr: https://localhost:8888
    schemes: 
      - https
    proto: http
  api2:
    addr: https://localhost:8080
    schemes: 
      - https
    proto: http

After that run

ngrok start --all

Upvotes: 4

marcio
marcio

Reputation: 696

Using free plan

  1. Actually, at 2023, I'm just supporting the original answer.

  2. And, showing how to edit the ngrok config file (ngrok.yml).

In CMD do:

ngrok config edit

Something like this:

version: "2"
authtoken: your_token_here
tunnels:
  any1:
    addr: 8888
    proto: http
  any2:
    addr: 8080
    proto: http
  any3:
    addr: 50000
    proto: http

Finally, again in CMD, start ngrok:

ngrok start --all

Be happy!

Upvotes: 10

Viraths
Viraths

Reputation: 950

This is how you can do using subdomain (Following @robe007 answer)

authtoken: your_auth_token
region: au
tunnels:
  frontend:
    proto: http
    addr: http://localhost:3000
    bind_tls: true
    subdomain: frontend-my-domain
    host_header: rewrite
  backend:
    proto: http
    addr: http://localhost:5001
    bind_tls: true
    subdomain: backend-my-domain
    host_header: rewrite

Then run ngrok start --all

Upvotes: 4

spidy
spidy

Reputation: 669

Go To These location :

  • OS X: /Users/example/.ngrok2/ngrok.yml
  • Linux: /home/example/.ngrok2/ngrok.yml
  • Windows: C:\Users\example\.ngrok2\ngrok.yml

then open yml file in notepad and paste below code and save.

authtoken: your_token
tunnels:
  first:
    addr: 3002
    proto: http    
  second:
    addr: 8080
    proto: http

now go to your ngrok location and run ngrok start --all

Upvotes: 26

King Friday
King Friday

Reputation: 26086

What worked for me with ngrok w/ multiple ports

So I had the issue where I needed the same domain origin policy to work for different ports but I was halted in my tracks because ultimately ngrok does not support this. They support a custom subdomain or custom domain but not on different ports since all must come through port 80 or 443.

Instead of quitting, I had to hack things together using nginx locally like so:

http {
    server {
        listen       7777;
        server_name  localhost;

        location / {
            proxy_pass http://127.0.0.1:5000;
        }

        location /api {
            proxy_pass http://127.0.0.1:8000;
        }
    }
}

I was fortunate the api server prefixed all calls "api" so I could route the api calls to a specific port and still serve the other traffic on another web server and you may not be so lucky.

I then configured the public web server to route all api calls to the same ngrok address and let ngnix sort it out.

I hope this may help you think of a combination of solutions to get there as thinking only one way may get you stuck as I was.

Upvotes: 43

Pedro Dionisio
Pedro Dionisio

Reputation: 105

Unfortunatly none of the following solutions worked for me but after multiple hours typing code with my nose i figured a way to solve this problem:

authtoken: your_private_token
tunnels:
  baseAPI:
    proto: http
    addr: https://localhost:44307/
    host_header: localhost:44307
  authAPI:
    proto: http
    addr: https://localhost:44305/
    host_header: localhost:44305

The diference is instead of using only the port on the addr field, i used the full link and added the host_header too.

Upvotes: 6

Josh Osborne
Josh Osborne

Reputation: 39

I used on ngrok process (on a reserved domain) pointing to port 80 locally.

ngrok http 80

Locally I have nginx running the following config. The only thing that matters to me are the 2 locations /admin and /api as those are what I was previously using multiple ngrok prcesses for. nginx allows you to use the same tunnel for separate locations.

server {
    listen 80 default_server;
    listen [::]:80 default_server;
    root /var/www/html;
    server_name _;

    location /admin {
        proxy_pass http://127.0.0.1:3005;
    }

    location /api {
        proxy_pass http://127.0.0.1:5001;
    }
}

Upvotes: 3

Related Questions