Ngrok错误'502坏网关'

问题描述 投票:19回答:9

使用任何类型的Web应用程序的东西都很新,我一直在尝试慢慢构建一个Facebook Messenger Bot。当我尝试使用ngrok时,我无法访问我给出的地址,即:

ngrok http 5000

是我在命令行中放置的,它正在返回:

ngrok by @inconshreveable

Session Status                online
Version                       2.1.18
Region                        United States (us)
Web Interface                 http://127.0.0.1:4040
Forwarding                    http://ea986ca5.ngrok.io -> localhost:5000
Forwarding                    https://ea986ca5.ngrok.io -> localhost:5000

Connections                   ttl     opn     rt1     rt5     p50     p90
                              0       0       0.00    0.00    0.00    0.00

但是,当我根据Facebook开发者页面的要求获取地址'https://ea986ca5.ngrok.io'时,它说:

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


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


The error encountered was: dial tcp [::1]:5000: connectex: No connection 
could be made because the target machine actively refused it.

这是我本地端口的问题吗?谢谢!

https ngrok http-tunneling
9个回答
17
投票

正如@ n​​jzk2应该说的那样,如果你没有运行的web服务器那么它就无法运行。如果你仍然感到困惑,我想让你更清楚。

ngrok的作用是使您的本地服务器(在localhost上运行)可用于外部世界(互联网的其余部分)。就其本身而言,它不是Web服务器。因此,对于您的bot开发,您需要在定义的端口上运行Web服务器(在您的情况下为5000)。然后,您可以将ngrok指向此端口,以便将发送到您的公共地址的请求重定向到在该端口上运行的程序。然后,Web服务器将接受并处理来自Facebook的请求


16
投票

这对我有用

ngrok.exe http -host-header =重写localhost:

例如ngrok.exe http -host-header =重写localhost:5219

我使用visual studio 2017不知道它是否会影响任何东西。


3
投票

尝试如下:

ngrok http 127.0.0.1:8080 -host-header="127.0.0.1:8080"


2
投票

如果您尝试使用ngrok指向https localhost URL,请设置代理。

看到这个github问题评论:

https://github.com/inconshreveable/ngrok/issues/448#issuecomment-414214242


2
投票

在我的例子中,它是Visual Studio 2017中的项目.Net Core 2.1是为了使用https和自签名证书而创建的。如果你不需要你的localhost是https,那么为我修复的是创建一个新的web项目并取消选中https。当您运行ngrok(ngrok http port-number-from-IISExpress)时,它会为您提供可用于开发的https URL。


0
投票

如果您有HTTP规则将HTTP重定向到HTTPS,则会发生此错误。

您可以为开发人员计算机禁用此功能,也可以根据X-Original-Host标头添加自定义规则:

我正在使用IIS重写插件,这就是我修复它的方法

 <rule name="Redirect to https" enabled="true" patternSyntax="ECMAScript" stopProcessing="true">
            <match url=".*" negate="false" />
            <conditions logicalGrouping="MatchAll">
              <add input="{HTTPS}" pattern="off" />

              <add input="{HTTP_X_Original_Host}" pattern="yourngrokname.ngrok.io" negate="true" />             

            </conditions>
            <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Found" />
          </rule>

0
投票

对我来说,将协议从http切换到tls是有效的,因为我只转发了一个安全的连接。我不需要重写标题。

只是为了上下文,我正在转发连接到Ubuntu 16上正在运行的docker容器。

PS:你仍然在浏览器中使用https访问地址,而不是tls。


0
投票

尝试显式设置localhost IP:

ngrok http 127.0.0.1:5000而不是ngrok http 5000

祝好运!


-1
投票

我必须使用(1)来自@ user6483104的答案和(2)使用我的项目中定义的不安全URL(与SSL URL即https)启动我的ngrok隧道。

在这里看到我的答案:How to configure Visual Studio 2017 to expose a non-encrypted port in a ASP.Net MVC https site

注意:如果我错误地存在默认的不安全URL,则此答案(How To Disable Https in Visual Studio 2017 Web Proj ASP.NET Core 2.0)声称有解除禁用安全URL的解决方案。我没有尝试过,因为在我现有的项目中已经定义了一个不安全的URL(因为我怀疑还有你的URL)

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.