Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exposing localhost to the internet via tunneling (using ngrok): HTTP error 400: bad request; invalid hostname

From previous versions of the question, there is this: Browse website with ip address rather than localhost, which outlines pretty much what I've done so far...I've got the local IP working. Then I found ngrok, and apparently I don't need to connect via the IP.


What I am trying to do is expose my website running on localhost to the internet. I found a tool that will do this: ngrok.

Running the website in visual studio, the website starts up on localhost/port#. I run the command "ngrok http port#" in the command line. Everything seems to start up fine. I generate a couple of URLs, and the ngrok inspection url (localhost:4040) works.

The only problem is that when I go to the generated URLs, I get an HTTP error 400: bad request invalid hostname. This is a different error than when I run "ngrok http wrongport#", which is a host not found error...so I think something good is happening. I just can't tell what...

Is there a step I am missing in exposing my site to the internet via the tunneling service? If there is, I can't find it in the ngrok documentation.

like image 686
Chris Avatar asked May 29 '15 17:05

Chris


People also ask

How do I open the tunnel Ngrok?

Chose "Start ngrok Tunnel" from the Visual Studio "Tools" menu, ngrok will start, and you'll see your app's new public URL. Here, ngrok gave us the URL of https://a9f03915.ngrok.io. Make sure you've started your application in Visual Studio and then try to open that URL in your browser.

What does bad request invalid hostname mean?

When testing the deployment with a single server IP, you get the error “Bad Request (Invalid Hostname)" on your browser. The issue occurs because IWSVA overwrites the Host header in the HTTP request with the IP or FQDN of the web server configured in IWSVA.


2 Answers

Troubleshot this issue with ngrok. In the words of inconshrevable, some applications get angry when they see a different host header than expected.

Running the following command should fix the problem:

ngrok http [port] -host-header="localhost:[port]" 
like image 73
Chris Avatar answered Sep 17 '22 15:09

Chris


Following command will fix the issue

ngrok http -host-header=localhost 8080 
like image 29
Sathish Avatar answered Sep 17 '22 15:09

Sathish