简体   繁体   English

Django Runserver无法从Google Cloud Platform运行

[英]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): 这个问题非常相似(但是不一样,因为我在google cloud上运行,我怀疑可能是这个问题的原因):

I am trying to set up an api running on a VM-instance on the google cloud platform. 我正在尝试在Google云平台上的VM实例上运行运行的api。 So far I got nginx working (when I go to the ip address it greats me with a welcome message). 到目前为止,我已经使nginx正常工作(当我转到ip地址时,会收到一条欢迎消息,这对我很有帮助)。 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). 系统检查未发现任何问题(0静音)。

February 06, 2019 - 09:27:13 二月06,2019-09:27:13

Django version 2.1.5, using settings 'my_api.settings.development' Django版本2.1.5,使用设置“ my_api.settings.development”

Starting development server at http://0.0.0.0:8000/ http://0.0.0.0:8000/上启动开发服务器

Quit the server with CONTROL-C. 用CONTROL-C退出服务器。

Which seems good, but when I go to any of the following pages (all of which I've listed under allowed_hosts): 看起来不错,但是当我转到以下任何页面时(所有这些页面我都列在allowed_hosts下):

  • 0.0.0.0:8000 0.0.0.0:8000
  • 127.0.0.1:8000 127.0.0.1:8000
  • < my ip address>:8000 <我的IP地址>:8000

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? 查找/解决我的网页无法加载的原因的下一步是什么?

You will need to create a firewall rule to allow inbound traffic on tcp port 8000 . 您将需要创建防火墙规则以允许tcp port 8000上的入站流量。

When creating the firewall rule, also specify a Target tag so that you can assign the firewall rule to the instance. 创建防火墙规则时,还请指定Target tag以便您可以将防火墙规则分配给实例。 Another option is to specify a service account such as Compute Engine default service account to assign the rule based upon identity. 另一个选项是指定服务帐户(例如Compute Engine default service account以根据身份分配规则。

Filtering by service account vs. network tag 按服务帐户和网络标签过滤

As @JohnHanley points out, I needed to create a firewall rule. 正如@JohnHanley指出的那样,我需要创建一个防火墙规则。

I did this by: 我这样做是:

  1. going to the google cloud platform console 转到Google Cloud Platform控制台
  2. firewall rules -> vpc network 防火墙规则-> vpc网络
  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) 将所有必要的IP地址添加到“源IP范围”(后跟/ 32,不确定原因,但这似乎可以解决问题)
  5. Under "Protocols and ports", I added tcp: 8000 在“协议和端口”下,我添加了tcp:8000
  6. I applied this to my server 我将此应用到我的服务器
  1. Make sure http traffic is enabled 确保启用了HTTP流量

  2. Make a firewall rule like so: 制定如下的防火墙规则:

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM