本文介绍了如何访问在Amazon ec2上运行的django应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我已经看过堆栈溢出+其他网站,但没有能够解决这个问题:因此发布这个问题!

So, I have looked around stack overflow + other sites, but havent been able to solve this problem: hence posting this question!

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

I have recently started learning django... and am now trying to run it on ec2.

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

I have an ec2 instance of this format: ec2-xx-xxx-xx-xxx.us-west-2.compute.amazonaws.com on which I have a django app running. I changed the security group of this instance to allow http port 80 connections.

我尝试以下列方式运行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,这似乎也没有帮助!

I did try to run it the django app the following ways: python manage.py runserver 0.0.0.0:8000 and python manage.py runserver ec2-xx-xxx-xx-xxx.us-west-2.compute.amazonaws.com:8000 and that doesnt seem to be helping either!

确保没有任何错误django的一方,我打开了另一个终端窗口,并进入实例,并向成功执行的localhost:8000 / admin发出了一个卷曲GET请求。

To make sure that there is nothing faulty from django's side, I opened another terminal window and ssh'ed into the instance and did a curl GET request to localhost:8000/admin which went through successfully.

我在哪里出错了感谢任何帮助!

Where am I going wrong? Will appreciate any help!

推荐答案

您正在端口8000上运行该应用程序,当该端口在实例上未打开时您只打开端口80)。

You are running the app on port 8000, when that port isn't open on the instance (you only opened port 80).

所以关闭端口80并从安全组打开端口8000,或在端口80上运行您的应用程序。

So either close port 80 and open port 8000 from the security group, or run your app on port 80.

在小于1024的端口上运行任何应用程序需要root权限;因此,如果您尝试以正常用户的身份执行 python manage.py runserver 0.0.0.0:80 ,则会收到错误。

Running any application on a port that is less than 1024 requires root privileges; so if you try to do python manage.py runserver 0.0.0.0:80 as a normal user, you'll get an error.

而不是使用 sudo python manage.py runserver 0.0.0.0:80 ,您有几个选项:

Instead of doing sudo python manage.py runserver 0.0.0.0:80, you have a few options:


  1. 运行django的预配置AMI映像(如从bitnami)。

  1. Run a pre-configured AMI image for django (like this one from bitnami).

配置前端服务器侦听端口80,然后代理请求到您的django应用程序。这里的常见堆栈是nginx + gunicorn +主管,解释了如何设置(连同一个永远是一个好习惯的虚拟环境进入)。

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).

这篇关于如何访问在Amazon ec2上运行的django应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 03:24