Nathan
Nathan

Reputation: 3648

Django runserver not working from google cloud platform

This question is very similar to (but is not the same because I am running on the google cloud, which I suspect may be cause of the issue):

I am trying to set up an api running on a VM-instance on the google cloud platform. So far I got nginx working (when I go to the ip address it greats me with a welcome message). When I run:

python3 manage.py runserver 0.0.0.0:8000

I get the following output:

Performing system checks...

System check identified no issues (0 silenced).

February 06, 2019 - 09:27:13

Django version 2.1.5, using settings 'my_api.settings.development'

Starting development server at http://0.0.0.0:8000/

Quit the server with CONTROL-C.

Which seems good, but when I go to any of the following pages (all of which I've listed under allowed_hosts):

The page won't load.

I´ve tried checking which ports are used using

netstat

And I've killed all programs using this port after which I restarted my program, but to no avail.

At this point, I've fixed everything suggested in other posts and I'm out of ideas. What would be the next step in finding/solving the cause of my internet page not loading?

Upvotes: 0

Views: 2132

Answers (3)

Taimoor Ahmad
Taimoor Ahmad

Reputation: 549

  1. Make sure http traffic is enabled

  2. Make a firewall rule like so:

enter image description here

Upvotes: 0

Nathan
Nathan

Reputation: 3648

As @JohnHanley points out, I needed to create a firewall rule.

I did this by:

  1. going to the google cloud platform console
  2. firewall rules -> vpc network
  3. + create firewall rule
  4. Added all necessary ip addresses to the "source ip ranges" (followed with /32, not sure why, but this is what seems to work)
  5. Under "Protocols and ports", I added tcp: 8000
  6. I applied this to my server

Upvotes: 0

John Hanley
John Hanley

Reputation: 81336

You will need to create a firewall rule to allow inbound traffic on tcp port 8000.

When creating the firewall rule, also specify a Target tag so that you can assign the firewall rule to the instance. Another option is to specify a service account such as Compute Engine default service account to assign the rule based upon identity.

Filtering by service account vs. network tag

Upvotes: 5

Related Questions