Ngrok errors '502 bad gateway'
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, i.e:
ngrok http 5000
is what I'm putting in the command line, and it's returning this:
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
But when I take the address 'https://ea986ca5.ngrok.io' as is required by the Facebook developer's page, it says:
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.
Is it a problem with my local port? Thanks!
Solution 1:
This worked for me
ngrok.exe http -host-header=rewrite localhost:<Your Port number>
e.g:
ngrok.exe http -host-header=rewrite localhost:5219
Im using visual studio 2017 dont know if it effects anthing.
Solution 2:
Try to explicitly set the localhost IP:
ngrok http 127.0.0.1:5000
instead of ngrok http 5000
Good luck!
Solution 3:
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
Solution 4:
I found I had to remove the quotes around the -host-header section to get this to work with the latest ngrok version (2.3.35):
ngrok http https://localhost:5001 -host-header=localhost:5001
(Currently not enough rep to add comments on any of the answers above)