63

When I am using ngrok & run url given by ngrok with following configuration:

  • my local url is : localhost:8080/someexample
  • my ngrok url is : http://f07d0862.ngrok.io/

it show this error:

Bad Request - Invalid Hostname  HTTP Error 400. 
user7440787
  • 813
  • 6
  • 21
Sunny
  • 631
  • 1
  • 5
  • 5

5 Answers5

178

Your web server is rejecting the request since it has different hostname.

Try ngrok http -host-header="localhost:8080"

Gregory
  • 5,355
  • 4
  • 27
  • 26
Bharat
  • 3,421
  • 1
  • 21
  • 21
  • This works perfectly, and is also a perfect solution for developing with Facebook Messenger webhooks. – Mike Upjohn Jun 13 '17 at 12:24
  • 8
    This answer is missing the quotation marks around the host-header value, and the colon, should be: `-host-header="localhost:8080"` – moritzg Jun 26 '17 at 08:47
  • Please refer the following link https://stackoverflow.com/questions/30535336/exposing-localhost-to-the-internet-via-tunneling-using-ngrok-http-error-400 – Pratyush Dhanuka Nov 22 '17 at 07:25
  • This is the command that worked for me is ngrok http -host-header=localhost 8080 Using the other command showed an error FAILED TO COMPLETE TUNNEL CONNECTION The connection to http://27900a3a1d5e.ngrok.io was successfully tunneled to your ngrok client, but the client failed to establish a connection to the local address host-header=localhost:33511. Make sure that a web service is running on host-header=localhost:33511 and that it is a valid address. The error encountered was: dial tcp: lookup host-header=localhost: no such host – Momodu Deen Swarray Apr 22 '21 at 13:57
38

This is the solution you want.

ngrok http 8080 -host-header="localhost:8080"
vijay
  • 581
  • 1
  • 7
  • 24
6

This worked for me:

ngrok http -host-header=localhost 8080
Lug
  • 390
  • 4
  • 14
0

For me it was this

ngrok.exe http https://localhost:44315 --host-header=localhost:44315
Augis
  • 1,813
  • 1
  • 16
  • 21
-2

May be you should turn off your firewall.

That works for me.

Joy Zhu
  • 416
  • 3
  • 9