18

I have a Vagrant box I'm using for local development. I'm working on a webhook, which is being called from outside; so I'm thinking of using ngrok.com to proxy requests to my Vagrant environment. I'm new to this ngrok thing.

I'm trying to figure out how to access ngrok's web interface, which is normally at http://127.0.0.1:4040. Of course, that doesn't work from my browser, because it's outside of the Vagrant box, so its localhost is not the Vagrant's localhost.

I (think I) have the Vagrant's IP address. I found it in a config.yaml file (yes, with an a), under vm: network: private_network: 192.168.nnn.nnn

Thanks for your help.

NotoriousWebmaster
  • 3,298
  • 7
  • 37
  • 49
  • I'm confused by your question. If you're running ngrok on your host machine, why can't you point your host's browser at localhost? Or are you running the proxy in the vagrant box? – Software Engineer Oct 27 '15 at 01:19
  • I'm, running ngrok in the guest machine. In Vagrant. To be fair, I haven't yet gotten a request through ngrok. For the time being, I'm just interested to see how I would get the web interface showing up in the host machine. – NotoriousWebmaster Oct 27 '15 at 01:50
  • 1
    If you read vagrant's 'networking' docs they start with exposing a web service via a port, then if that's not enough it documents how to set up a static ip for the box, and finally how to setup and use dynamic ips. You'd probably be fine with port forwarding. – Software Engineer Oct 27 '15 at 01:52
  • 1
    Also, are you aware of WireShark? – Software Engineer Oct 27 '15 at 01:52
  • @SoftwareEngineer: I was on the other hand confused with your comment. Ngrok is running in the **guest** where there is only command line and ngrok's web interface shoud be accessed from the browser running in the host. The accepted anwser doesn't answer the question - the correct answer is the one describing `web_addr: 0.0.0.0:4040` parameter for exposing the ngrok's web interface to other computers in local network. – Chupo_cro Jun 11 '21 at 22:35

5 Answers5

54

When trying to access a site in a VM, put ngrok in the host machine, and invoke it with:

ngrok http -host-header=rewrite mydomain.com:80

You'll need to access your site (in host machine's browser) with:

http://123456.ngrok.io

But it will rewrite it to mydomain.com.

And you'll be able to access your ngrok dashboard (in host machine's browser) with:

http://127.0.0.1:4040

Docs at https://ngrok.com/docs#host-header. Best of luck!

NotoriousWebmaster
  • 3,298
  • 7
  • 37
  • 49
  • This doesn't answer the question whish was how to access ngrok web interface which runs in the **guest**. – Chupo_cro Jun 11 '21 at 22:26
25

Your problem is this one: https://github.com/inconshreveable/ngrok/issues/153

You have to create a config file with the following content:

web_addr: 0.0.0.0:4040

And then run ngrok as this:

ngrok http 3000 -config=/path/to/ngrok.conf

Now you can access the web interface from your browser using the following addresses: http://vagrantip:4040 or http://vagranthostname:4040

For example, http://192.168.33.34:4040 or http://site.dev:4040 if your /etc/hosts is configured in this way

More info on ngrok config file is here: https://ngrok.com/docs#config

Evandro Saroka
  • 490
  • 5
  • 5
6

Change your configuration nano ~/.ngrok2/ngrok.yml by adding this:

web_addr: 0.0.0.0:4000

This will open access to your ngrok dashboard to your host machine.

Anatoly Mironov
  • 7,356
  • 1
  • 26
  • 27
1

add following line to your Vagrantfile

config.vm.network "forwarded_port", guest: 4040, host: 8080

then you can access at http://localhost:8080 or http://127.0.0.1:8080 from host system. you can take help of Vagrant Documentation .

or

go to your guest machine using command:

vagrant ssh vmname

and check ip of guest machine using ifconfig. vagrant use a default network and assign one ip to guest machine so using that ip you can access web interface from your host http://vagrantip:4040

or

you can create or assign public or private network IP. refer vagrant Networking

pl_rock
  • 14,054
  • 3
  • 30
  • 33
  • tried both the eth0 (10.0.x.x) and eth1 (192.168.x.x) IP addresses in the `http://vagrantip:4040` suggestion, and they both time out. I'll try the Vagrantfile suggestion next; though that one will get tracked by git, and shared with the rest of the team. – NotoriousWebmaster Oct 27 '15 at 15:31
  • what is output of command `sudo netstat -tulnp | grep 4040` in guest vagrant machine – pl_rock Oct 27 '15 at 15:33
  • `4:tcp 0 0 127.0.0.1:4040 0.0.0.0:* LISTEN 10854/ngrok` – NotoriousWebmaster Oct 27 '15 at 15:36
  • you service running but on localhost so first method will work and you can access it by http://hostip:8080 also . if you want 1o access on 192.168.x.x or 10.0.x.x then do binding your service with ip . somewhere in your ngrok config is localhost . so change it with this ip. i don't know about ngrok so i can't help in that config part. check this https://ngrok.com/docs#custom-domains if helpful – pl_rock Oct 27 '15 at 15:51
  • Yeah, looked through the ngrok docs again, and nothing jumped out at me. Custom domains is a paid feature, and I don't yet have a paid acct on that service. I'm going to look at the Vagrantfile next. – NotoriousWebmaster Oct 27 '15 at 16:28
  • as i told i don't know about ngrok but have you tried `ngrok http 192.168.x.x:8080` refer https://ngrok.com/docs#expose if help . – pl_rock Oct 27 '15 at 16:41
  • Thanks for your help pl_rock. Got assistance from ngrok developer and was able to get things happening. – NotoriousWebmaster Oct 27 '15 at 19:00
  • @pl_rock: The question wasn't about how to expose the web server running on the machine but was about exposing the **ngrok's web interface** (because ngrok is running in the machine without GUI and web interface has to be accessed from some other computer). The answer is **web_addr: 0.0.0.0:4040** parameter. – Chupo_cro Jun 11 '21 at 22:52
0

(This is a note to my future self and anyone who might face similar issue)

I'm using Vagrant, and I access my local websites (which are running in Vagrant) from host's browser URL, like so https://my.local.site . I'm using multiple ports, each port points to different local website (for example, https://my.local.site:1111 points to site1, https://my.local.site:2222 points to site2, etc). So to have ngrok work with one specific site (let's say site1, which is using port :1111), all I needed to do is run ngrok (from host) like so:

ngrok http my.local.site:1111

Now in host browser, I can use ngrok link to access it publicly, like so:

https://11-22-33-44-55.ngrok.io/people/person
# the above line will act as if I opened URL from browser https://my.local.site:1111/people/person

If I want to access my other local websites, I need to run multiple ngroks the same way for each port (but note: ngrok free account allows only 1 simultaneous active agent).

evilReiko
  • 19,501
  • 24
  • 86
  • 102