2

I am working on my first Django project. Trying to connect to the auto-grader for my course through ngrok.I ran python manage.py runserver. I can see the website at http://127.0.0.1/8000 and it is working. I tried the command ngrok http 80 and got a forwarding URL. When I try to see the Http://xxxxxxxngrok.io/127.0.0.1/8000 I get the following error:

"The connection to http://444e-2600-1700-5egb-70c0-c843-879c-12ad-2b03.ngrok.io was successfully tunneled to your ngrok client, but the client failed to establish a connection to the local address localhost:80.

Make sure that a web service is running on localhost:80 and that it is a valid address.

The error encountered was: dial tcp [::1]:80: connectex: No connection could be made because the target machine actively refused it.

I typed netstat after running the runserver command. It shows 127.0.0.1/8000 with a state "listening"

How can I resolve this?"

ArNY
  • 65
  • 1
  • 9

1 Answers1

3

If you are hosting your upstream service at http://127.0.0.1:8000, then the command you would use to start ngrok should be: ngrok http 8000. The link that is provided to you by ngrok should work as is, as in you do not have to append anything to the end of it as you describe in your issue.

If it still doesn't work, try rewriting the host header using: ngrok http 8000 --host-header rewrite.

Check out the ngrok docs for more info: https://ngrok.com/docs

Edit: Forgot to mention if you want to add logic directly to your Django app for controlling the agent, check out this example: https://pyngrok.readthedocs.io/en/latest/integrations.html#django

Russ Savage
  • 548
  • 2
  • 14
  • Thanks. BTW I tried both of these by themselves without appending 127.0.0.1.8000, google chrome showed me a red-colored page with a phishing warning.. But it seems to work when I append the 127.0.0.1.8000 to the address ngrok gave me. I am new to this subject of ports. I thought port 80 is a generic port that covers 8000, 8080, etc.. Is that not correct? Can you please explain this a little and where can I read more about this to understand these things a little better? – ArNY Mar 24 '22 at 00:56
  • I suspect that Chrome is doing some sort of URL hashing to identify possible malicious websites, and by adding the additional stuff at the end, it evades their filter somehow. ngrok doesn't need you to append 127.09.0.1:8000 to the end of the url to work. re: ports Each service you run on your local machine usually gets its own port number. It's how your computer knows where to send incoming traffic (127.0.0.1 port 80 goes to this service, port 8080 goes to a different service). The Wikipedia page is a good resource: https://en.wikipedia.org/wiki/Port_(computer_networking) – Russ Savage Mar 25 '22 at 15:51