ngrok icon indicating copy to clipboard operation
ngrok copied to clipboard

Getting an error as "502 Bad Gateway"

Open tanvishah-syn opened this issue 7 years ago • 27 comments

Hi, I have installed ngrok version 2.2.8 on mac. I am trying to send http request to server using postman. A request is sending correctly. I am able to see headers in http://127.0.0.1:4040 ngrok web interface. I am getting a response as " 502 Bad Gateway. The server returned an invalid or incomplete response." How would I debug ngrok request?

tanvishah-syn avatar Feb 07 '18 12:02 tanvishah-syn

This just started happening to me. Any suggestions/fixes? Nothing knowingly changed on my end as of late...

dannyfreed avatar Feb 09 '18 22:02 dannyfreed

bump on this, it seems to happen when i paste it into the facebook sharing debugger

scrummitch avatar Mar 01 '18 03:03 scrummitch

Getting this error too -- anyone resolution..?

jefflam avatar Mar 06 '18 09:03 jefflam

+1. v2.2.8 running on windows 10.

harksha avatar Mar 21 '18 12:03 harksha

+1 v2.2.8, v2.2.9, and v2.2.7 on windows server 2008. Getting this text:

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

Joe118 avatar Apr 05 '18 20:04 Joe118

Well I am able to see localhost:4040 (which is the introspection page) through the tunnel, so its some disagreement between ngrok and my application. It'd be really nice if ngrok would log somewhere WHAT it did not like.

Joe118 avatar Apr 05 '18 21:04 Joe118

Try running it without ssl

harksha avatar Apr 05 '18 21:04 harksha

Thanks @harksha -- examining the documentation for how to ;)

EDIT -- you probably mean adding -bind-tls=false -- that did not work:

Incorrect Usage: flag provided but not defined: -bind-tls

Joe118 avatar Apr 05 '18 21:04 Joe118

@harksha I see you posted 10 days ago that you had this problem, would appreciate figuring out which version of ngrok worked for you and what combo of command line options :)

THANKS!

Joe118 avatar Apr 05 '18 21:04 Joe118

@Joe118 No, I mean you need to disable ssl on your local solution, so it runs on http, not https

harksha avatar Apr 06 '18 06:04 harksha

@harksha my http server already was running on http only.

Anyways I'm pretty convinced this is not a problem with ngrok because I can direct ngrok to forward port 4040 (its own diagnostic) and then I can see it fine on the ngrok.io subdomain. So its something to do with my http server.

I still can't figure out why the port forwarding would cause a 502, because I can see the web page when I run a web browser on the same machine and look at it via localhost:8000/index.html

Joe118 avatar Apr 06 '18 07:04 Joe118

@Joe118 ok, I thought that's what fixed it, but you're right, it might be port forwarding(which got stopped when I removed ssl). Don't have any idea why, tho'.

harksha avatar Apr 06 '18 08:04 harksha

@harksha thanks!

I'm going to chat with the people who wrote the embedded web server I'm using -- EmbedIO. I'll report back here if they find anything.

Joe118 avatar Apr 08 '18 03:04 Joe118

@harksha and @inconshreveable I opened https://github.com/unosquare/embedio/issues/154 on the EmbedIO project's github repository.

Joe118 avatar Apr 09 '18 19:04 Joe118

OK its not an ngrok bug and not a bug in EmbedIO either. :)

The issue is that when you tell a webserver to serve pages on http://localhost:8787/ (as an example), some also bind http://127.0.0.1:8787/ and some do not. There's no rule that the webserver has to, but also no rule that it does NOT have to. So to be sure ngrok will tunnel your web server, you have to bind both localhost:8787 and 127.0.0.1:8787

@inconshreveable , so now the question becomes, did anything change in ngrok recently to require both localhost and 127.0.0.1 to be bound?

Joe118 avatar Apr 09 '18 19:04 Joe118

Hey so you will need to start your server manually so that it listens on the port you want. Run php -S 0.0.0.0:5000 -t public/ on linux command line with 5000 being the port you wanna feed to ngrok. Then go to ngrok and run ngrok http 5000

That will work

sharonmalio avatar May 23 '18 07:05 sharonmalio

Switching the protocol from http to tls worked for me.

andyfaizan avatar Jul 30 '18 14:07 andyfaizan

switching from http to tls killed the 502 error for me, but now i'm getting an invalid hostname 4xx error

seannybgoode avatar Sep 05 '18 21:09 seannybgoode

Also getting the bad gateway for connecting to localhost running an HTTPS (TLS) server on port 9011. When switching to HTTP (not HTTPS) it works.

Any new ideas?

syberkitten avatar Jan 03 '19 12:01 syberkitten

This is what worked for me. Spent hours searching for it. Some of the above solution didn't work. I would recommend this order. ngrok http https://localhost:5443 -host-header="localhost:5443" -subdomain=<If you have pro> ngrok http https://localhost:5443 -host-header="localhost:5443"

amardesaiZT avatar Aug 09 '19 01:08 amardesaiZT

Ngrok expects a web server to be running on localhost. If there isn’t a server running, you’ll see a 502 error .

nanddeepn avatar Sep 08 '19 06:09 nanddeepn

I also ran into the same issue with testing some webhooks locally. In my case, I had to make sure ngrok was tunneling to my local development server running on HTTPS, not HTTP.

karls avatar Oct 06 '19 15:10 karls

Hi tanvish,

502 gateway error occurs because ngrok not able to receive any reponse from Localhost.

The things need to be done is : 1.Start a webserver in a Port 2.Trigger ngrok command in that Port.

What i have done is -> Started a tomcat Web Server in 8080. -> Then Triggered ngrok http 8080.

It works really Kool .. Try this .. Hope it works for You .

dhanaSiggie1111 avatar Oct 22 '19 05:10 dhanaSiggie1111

just use ngrok http port_number it works

Nightrider0098 avatar Dec 31 '19 08:12 Nightrider0098

For linux users w/ default port 80:

sudo apt-get install apache2
sudo service apache2 start
ngrok http 80
  • Make sure port 80 is allowed through firewall
  • place sample html file in /var/www/html/index.html

phelps-matthew avatar Jan 06 '20 19:01 phelps-matthew

Sudo not install on Android phone when i using termux .

mudirajesh avatar Jan 10 '20 08:01 mudirajesh

ngrok http 8080

This works for me! :+1:

heniotierra avatar Nov 23 '20 03:11 heniotierra

Thank you for opening this issue! As of April 2016, the ngrok service has permanently moved to https://ngrok.com/. To join the community and file bug reports or feature enhancements for the ngrok agent, please go to https://github.com/ngrok/ngrok.

This repository is no longer actively maintained and will be archived soon to reduce confusion with the latest ngrok versions. We thank you for the continued support of ngrok and look forward to seeing you over at ngrok.com and the ngrok Community Repo.

russorat avatar May 09 '24 19:05 russorat