Embedio: http://localhost:9696/ works locally but tunneling through ngrok causes a 502 status

Created on 9 Apr 2018  路  6Comments  路  Source: unosquare/embedio

Issue:

I'm using EmbedIO 1.13.0 and Swan.Lite 1.28.0 on Windows 2008 Server R3. I'll put the code I use to start the web server at the end. Apart from that code I have written no other C# code to use the server or extend it with handlers.

The problem I'm experiencing is http://localhost:9696/index.html is showing just fine on my local browser, but when I'm tunneling out of my "NAT prison" with ngrok (see https://ngrok.com/ ) the browser shows:

------------- response begins -------------
502 Bad Gateway
The server returned an invalid or incomplete response.
------------- response ends -------------

Hypothesis:

There's a lot more detail below; based on some evidence (see below) I am suspecting that ngrok thinks the response from EmbedIO's StaticFilesModule is binary and that might be causing the 502?

Do I need to send some headers back with the static file to indicate the mime type? If yes, how? And should the StaticFilesModule not do that, figuring the mine type to indicate based on the file extension?

Things I tried (see below) that might indicate there's a problem in EmbedIO:

  • ngrok is able to show its own web console remotely (that is, ngrok.exe http 4040 works fine)
  • I tried two other programs similar to ngrok -- serveo ( https://serveo.net ) with putty, portmap.io -- and they also produce a 502 status
  • I tried a different embedded web server library -- https://github.com/Relfos/synk-server -- and that works just fine with ngrok, serveo, and portmap.io.

More Details:

Checking the ngrok raw log I can see that the remote site sent:

------------- request begins -------------
GET /index.html HTTP/1.1
Host: 6d0b157b.ngrok.io
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,/;q=0.8
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.9
X-Forwarded-Proto: https
X-Forwarded-For: 216.108.226.10
------------- request ends -------------

And the server responded with the content of the static file

Looking on ngrok's web console I see no content sent back, but there's a curious message:

Binary response not displayed

Does EmbedIO produce a response that somehow makes ngrok think the response it got is binary? Do I need to send some headers back with the static files to indicate the mime type? If yes, how? And should the StaticFilesModule not do that, figuring the mine type to indicate based on the file extension?

C# Code:

Anyways, here's the very simple code I am using to start the EmbedIO server:

  string url = "http://localhost:9696/";
  WebServer srv = new WebServer(url);
  srv.RegisterModule(new StaticFilesModule(localFiles));
  srv.RunAsync();

End

Thanks for looking at this. I really want to use EmbedIO but I cannot use it if I can't display pages on a publicly available URL.

bug

Most helpful comment

ngrok http -host-header="localhost:9696" 9696 should make it so you don't need to run as admin. (trying to solve a different problem and ran across this)

All 6 comments

@geoperez wow, response in less than a minute! Is this a known problem that was already reported by someone else?

I am Joe.M.Finn on facebook, would love to chat via messenger if you want me to try more scenarios.

I'm getting Bad Request

image

Try to bind to all the network interfaces using http://*:8787. You will need run it as admin.

I'm running the Sample http://b7af8d28.ngrok.io

WOW that fixed it! But sad it requires admin -- there's probably no way around it. Anyways its working now, YAHOO!

Check it out here https://6d0b157b.ngrok.io/

Just for curiosity, what was the issue, and is it a bug or should I always use http://*:8787/ ?

You guys give amazing support!!!!!!!!!!!!!!!!!!!!!!

It's not a bug, this is how Windows handle the network binding. Usually, localhost will allow HTTPSys look for a resource listening 127.0.0.1, but I think ngrok is trying to resolve localhost by IPv6.

ngrok http -host-header="localhost:9696" 9696 should make it so you don't need to run as admin. (trying to solve a different problem and ran across this)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

simohr picture simohr  路  5Comments

chyyran picture chyyran  路  6Comments

bufferUnderrun picture bufferUnderrun  路  4Comments

Dewyer picture Dewyer  路  7Comments

erossini picture erossini  路  5Comments