Ngrok configure multiple port in same domain

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


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.


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:

  • To find your default config file read https://ngrok.com/docs#config-default-location.

  • All plans issues an auth token. You can find yours in the web dashboard: https://dashboard.ngrok.com/get-started