Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using ngrok with IISExpress on windows

Tags:

iis

ngrok

I'm used to using a Mac, and ngrok is a breeze; all you need to do is specify a port, but I'm new to IISExpress, and I can't figure out how to use ngrok and/or IIS correctly. To be clear, I've inherited a Windows machine from a coworker (who has left the company) and the set up works great locally.

The local url is similar to:

thing.somedomain.com

In the bindings section of IIS, I've got:

Type    Host Name               Port   IP Address
http    thing.somedomain.com    80     *

I've used this page for reference: https://www.twilio.com/blog/2014/03/configure-windows-for-local-webhook-testing-using-ngrok.html

The instructions seem reasonable, but they don't work for me. These instructions indicate that the file applicationhost.config needs to be altered for IIS. I have found this file, and found the correct section for the site I need to ngrok. The binding info does not match what's in the IIS gui though:

<binding protocol="http" bindingInformation="*:4085:localhost" />

As per the instructions, I have added:

<binding protocol="http" bindingInformation="*:4085:whatever.ngrok.io" />

(Here every time I run ngrok on windows I get ngrok.io instead of ngrok.com, which seems odd. I've tried accessing both ways with no luck.)

I have restarted the site on IIS (in the actions menu). When I try to access the ngrok url from a remote machine, ngrok returns 502 bad gateway, and the remote machine shows:

Failed to complete tunnel connection

The connection to http://whatever.ngrok.io was successfully tunneled to your ngrok client, but the client failed to establish a connection to the local address localhost:4085.

Make sure that a web service is running on localhost:4085 and that it is a valid address.

The error encountered was: dial tcp 127.0.0.1:4085: ConnectEx tcp: No connection could be made because the target machine actively refused it.

When I try to go to localhost:4085 locally, I get "This webpage is not available". When I try to go to localhost:80, I get a redirect to a different site the IIS is serving. When I try 127.0.0.1:80, I get a 404 error.

I have tried using netstat -a -b, and have tried all of the ports associated with 127.0.0.1, and nothing turns up the correct site (yet still thing.somedomain.com still works correctly).

I'm completely mystified, and don't know what to try next, or where the problem lies (in how I'm starting ngrok, in how I'm accessing ngrok, in how the bindings are mapped, in how IIS restarts, a firewall issue, or some other voodoo). This should be bloody simple!

like image 325
Katharine Osborne Avatar asked Apr 30 '15 16:04

Katharine Osborne


People also ask

Can you use Ngrok as a VPN?

We can use ngrok to turn private (VPN required) URLs into temporary and public ones. We can use mitmproxy to make changes to the pages and hide and/or obfuscate the content and preserve its privacy.

Does Ngrok require port forwarding?

Your localhost development server is mapped to an ngrok.io sub-domain, which a remote user can then access. There's no need to expose ports, set up forwarding, or make other network changes. The ngrok client software is available for Windows, macOS, and Linux.


2 Answers

There is a way to make it easier. Let's say your IISExpress website is http://localhost:63254

Just start ngrok like this:

ngrok http -host-header=rewrite localhost:63254
like image 105
Pavel Kovalev Avatar answered Oct 10 '22 20:10

Pavel Kovalev


So it turns out that there was nothing to change in the ApplicationHost.config file, AND I was looking at the wrong ApplicationHost.config file (the real file is normally hidden from view in C:/Windows/System32/inetsrv/Config, but you can open it in Notepad from a Command Prompt that has elevated privileges (Run as Administrator)). The actual binding info was:

<binding protocol="http" bindingInformation="*:80:thing.somedomain.com" />

Which is what matched what IIS was showing. That said, what I needed to change was how I invoked ngrok:

ngrok http -host-header=thing.somedomain.com:80

And that was it. I also allowed external traffic to the hostname with this:

netsh http add urlacl url=http://thing.somedomain.com/ user=everyone
like image 44
Katharine Osborne Avatar answered Oct 10 '22 21:10

Katharine Osborne