【发布时间】:2021-09-11 23:15:24
【问题描述】:
本教程here 展示了如何在 AWS EC2 上启动开发服务器:
ALLOWED_HOSTS=['EC2_DNS_NAME']
...
python manage.py runserver 0.0.0.0:8000
In a browser, navigate to public DNS of the instance, make sure to append port “8000” at the end and if everything was properly configured, it will show the index page of the application.
For example: www.ec2dnsname.com:8000
我的公共 IPv4 DNS 是这种形式:
ec2-xx-xxx-xx-xxx.region.compute.amazonaws.com
所以,在我的settings.py
ALLOWED_HOSTS=['ec2-xx-xxx-xx-xxx.region.compute.amazonaws.com']
并在 EC2 终端中运行:
python manage.py runserver 0.0.0.0:8000
但是,当我尝试到达这个地址时:
www.ec2-xx-xxx-xx-xxx.region.compute.amazonaws.com:8000
什么都没有显示 (The page took too long to respond)。
这是尝试在 AWS EC2 上运行开发服务器的完整且正确的方法吗?
@Iam_batman 响应后更新:以下是附加到我的 EC2 实例的安全组设置:
All TCP TCP 0 - 65535 0.0.0.0/0 –
All TCP TCP 0 - 65535 ::/0 –
Port Range 似乎涵盖了一切。我仍然无法从开发服务器访问索引页。
另外,我的 AWS 账户是工作场所账户,而不是个人账户。如果我按照下面的@iam_batman 设置,使用 HTTP 和 SSH 协议,我将分别拒绝访问端口 80 和 22。
更新:为了进一步测试,我运行 curl 命令如下:
curl http://ec2-xx-xxx-xx-xxx.region.compute.amazonaws.com:8000
我获得了标准 Django 索引页面(带有宇宙飞船的页面)的完整 HTML 代码。这意味着该网站已经在该地址可用。但是由于某种原因,它没有在浏览器上呈现?
【问题讨论】:
-
对我来说似乎有效。您是否设置了 ec2 入站流量规则以允许 8000 端口?
标签: django amazon-web-services amazon-ec2