问题
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
回答1:
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#default-config-location.
All plans issues an auth token. You can find yours in the web dashboard: https://dashboard.ngrok.com/get-started
回答2:
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.
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.
回答3:
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;
}
}
来源:https://stackoverflow.com/questions/25522360/ngrok-configure-multiple-port-in-same-domain