Ngrok errors '502 bad gateway'

前端 未结 15 1422
谎友^
谎友^ 2020-12-15 03:16

Quite new to using any sort of Web App stuff, and I\'ve been trying to slowly build a Facebook Messenger Bot. When I try to use ngrok I can\'t visit the address I\'m given,

相关标签:
15条回答
  • 2020-12-15 03:17

    For me, switching the protocol from http to tls worked since I am forwarding only a secure connection. I didn't need to rewrite the header.

    Just for context, I am forwarding a connection to a running docker container on Ubuntu 16.

    PS: You still access the address using https in the browser, not tls.

    0 讨论(0)
  • 2020-12-15 03:23

    Try like below:

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

    0 讨论(0)
  • 2020-12-15 03:23

    This error can occur if you have an HTTP rule to redirect HTTP to HTTPS.

    You can disable this for your developer machine or add a custom rule based on the X-Original-Host header:

    I'm using the IIS rewrite plug-in and this is how I fixed it

     <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 讨论(0)
  • 2020-12-15 03:26

    Just as @njzk2 should have said, if you don't have a web server running so it cannot work. I would like to make it clearer to you, if you are still confused.

    What ngrok does, is to make your local server (running on localhost) to be available to the outside world (rest of the internet). On its own, it is not a web server. So for your bot development you need to have a web server running on a defined port (which in your case is 5000). Then you can point ngrok to this port so that it will redirect requests sent to your public address to the program running on that port. The web server will then accept and handle requests from Facebook

    0 讨论(0)
  • 2020-12-15 03:28

    I had to use both (1) the answer from @user6483104 and (2) start my ngrok tunnel using the unsecured URL defined in my project (vs the SSL URL ie. https).

    See my answer here: How to configure Visual Studio 2017 to expose a non-encrypted port in a ASP.Net MVC https site

    Note: If I'm wrong about there being a default unsecured URL, this answer (How To Disable Https in Visual Studio 2017 Web Proj ASP.NET Core 2.0) claims to have a solution for disabling the secured URL. I didn't try it because there was already an unsecured URL defined in my existing project (as I suspect there is with yours as well)

    0 讨论(0)
  • 2020-12-15 03:29

    Try to explicitly set the localhost IP:

    ngrok http 127.0.0.1:5000 instead of ngrok http 5000

    Good luck!

    0 讨论(0)
提交回复
热议问题