4

因此,我查看了堆栈溢出+其他站点,但未能解决此问题:因此发布此问题!

我最近开始学习 django ......现在正试图在 ec2 上运行它。

我有一个这种格式的 ec2 实例:ec2-xx-xxx-xx-xxx.us-west-2.compute.amazonaws.com,我在上面运行了一个 django 应用程序。我更改了此实例的安全组以允许 http 端口 80 连接。

我确实尝试通过以下方式运行 django 应用程序:python manage.py runserver 0.0.0.0:8000 和 python manage.py runserver ec2-xx-xxx-xx-xxx.us-west-2.compute.amazonaws.com :8000 这似乎也没有帮助!

为了确保 django 方面没有任何问题,我打开了另一个终端窗口并 ssh 进入实例并向 localhost:8000/admin 发出 curl GET 请求,该请求成功通过。

我哪里错了?将不胜感激任何帮助!

4

2 回答 2

10

您正在端口 8000 上运行应用程序,而该端口未在实例上打开(您仅打开端口 80)。

因此,要么关闭端口 80,然后从安全组打开端口 8000,要么在端口 80 上运行您的应用程序。

在小于 1024 的端口上运行任何应用程序都需要 root 权限;因此,如果您尝试以python manage.py runserver 0.0.0.0:80普通用户的身份进行操作,则会出现错误。

而不是做sudo python manage.py runserver 0.0.0.0:80,你有几个选择:

  1. 为 django 运行一个预配置的 AMI 映像(比如来自 bitnami 的这个)。

  2. Configure a front end server to listen on port 80, and then proxy requests to your django application. The common stack here is nginx + gunicorn + supervisor, and this blog post explains how to set that up (along with a virtual environment which is always a good habit to get into).

于 2013-11-12T05:49:35.720 回答
0

Make sure to include your IPv4 Public IP address in the ALLOWED_HOSTS section in Django project/app/settings.py script...

于 2018-08-13T16:59:17.967 回答