inconshreveable / ngrok

Unified ingress for developers
https://ngrok.com
Other
24.15k stars 4.26k forks source link

Getting an error as "502 Bad Gateway" #475

Closed tanvishah-syn closed 5 months ago

tanvishah-syn commented 6 years ago

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?

dannyfreed commented 6 years ago

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

scrummitch commented 6 years ago

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

jefflam commented 6 years ago

Getting this error too -- anyone resolution..?

harksha commented 6 years ago

+1. v2.2.8 running on windows 10.

Joe118 commented 6 years ago

+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 commented 6 years ago

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.

harksha commented 6 years ago

Try running it without ssl

Joe118 commented 6 years ago

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 commented 6 years ago

@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!

harksha commented 6 years ago

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

Joe118 commented 6 years ago

@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

harksha commented 6 years ago

@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'.

Joe118 commented 6 years ago

@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 commented 6 years ago

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

Joe118 commented 6 years ago

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?

sharonmalio commented 6 years ago

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

andyfaizan commented 6 years ago

Switching the protocol from http to tls worked for me.

seannybgoode commented 6 years ago

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

syberkitten commented 5 years ago

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?

amardesaiZT commented 5 years ago

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= ngrok http https://localhost:5443 -host-header="localhost:5443"

nanddeepn commented 5 years ago

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

karls commented 5 years ago

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.

dhanaSiggie1111 commented 4 years ago

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 .

Nightrider0098 commented 4 years ago

just use ngrok http port_number it works

phelps-matthew commented 4 years ago

For linux users w/ default port 80:

sudo apt-get install apache2
sudo service apache2 start
ngrok http 80
mudirajesh commented 4 years ago

Sudo not install on Android phone when i using termux .

heniotierra commented 3 years ago
ngrok http 8080

This works for me! :+1:

russorat commented 5 months ago

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.