13

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!

4

2 回答 2

12

所以事实证明 ApplicationHost.config 文件中没有任何改变,而且我正在查看错误的 ApplicationHost.config 文件(实际文件通常隐藏在 C:/Windows/System32/inetsrv/Config 中,但是您可以从具有提升权限的命令提示符(以管理员身份运行)在记事本中打开它。实际的绑定信息是:

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

这与 IIS 显示的内容相匹配。也就是说,我需要改变的是我调用 ngrok 的方式:

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

就是这样。我还允许通过以下方式访问主机名的外部流量:

netsh http add urlacl url=http://thing.somedomain.com/ user=everyone
于 2015-05-01T16:13:54.300 回答
4

有一种方法可以使它更容易。假设您的 IISExpress 网站是http://localhost:63254

ngrok这样开始吧:

ngrok http -host-header=rewrite localhost:63254
于 2021-01-22T22:14:37.183 回答