66

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
  • 831
  • 7
  • 22
Sunny
  • 661
  • 1
  • 5
  • 5

6 Answers6

181

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

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

Gregory
  • 6,514
  • 4
  • 28
  • 26
Bharat
  • 3,491
  • 1
  • 22
  • 22
  • 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
  • I needed to use two leading dashes on ngrok 3.0.6: `--host-header="localhost:8080"` – Holistic Developer Aug 02 '22 at 12:53
40

This is the solution you want.

ngrok http 8080 -host-header="localhost:8080"
vijay
  • 701
  • 2
  • 12
  • 26
6

This worked for me:

ngrok http -host-header=localhost 8080
Lug
  • 420
  • 5
  • 15
3

For me it was this

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

If getting -o flag something error try with double -

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

Captain_Levi
  • 87
  • 1
  • 5
-2

May be you should turn off your firewall.

That works for me.

Joy Zhu
  • 446
  • 4
  • 9