初学者安装EC2 bitnami栈上的第一个应用程序

初学者问题在这里。 对于一直在做这些事情的人来说,这可能是很明显的。 但是我在设置运行在EC2 bitnami实例上的django时遇到了困难。

我设置我的服务器,我可以login。只是为了testing这个我安装民意调查的例子。 下面是我执行的命令来运行。

问题:

  • 我在这里做错了什么?
  • 我如何让我的基本民意调查页面显示?
  • 另外,有什么最佳实践,我应该遵循configuration一个活的服务器?

任何一步一步都非常感激。

—-命令—–

$ cd /opt/bitnami/projects/Project #directory already exists $ sudo python manage.py startapp polls $ sudo chown -R bitnami * # tired of doing sudo.. Good move or not? $ vim polls/models.py # matches the example $ vim polls/views.py #see below $ vim urls.py # added: (r'^polls/$', 'polls.views.index'), $ vim settings.py #added polls $ python manage.py syncdb # tables created successfully $ python manage.py runserver # server started # Now I open my browser and go to: http://10.206.xxx.yyy:8000/polls/ # also tried ports 8080 and 80 # Error: unable to connect 

——- views.py ———–

 # Create your views here. from django.http import HttpResponse def index(request): return HttpResponse("Hello, world. You're at the poll index.") 

我也尝试下面的评论没有成功。

港口80

 $ sudo python manage.py runserver 0.0.0.0:80 Django version 1.3, using settings 'Project.settings' Development server is running at http://0.0.0.0:80/ Quit the server with CONTROL-C. Error: That port is already in use. 

端口8000

 $ python manage.py runserver 0.0.0.0:8000 #also tried python manage runserver 10.206.xxx.yyy:8000 (same results) Django version 1.3, using settings 'Project.settings' Development server is running at http://10.206.xxx.yyy:8000/ in browser: http://10.206.xxx.yyy:8000 result: Firefox can't establish a connection to the server at 10.206.xxx.yyy:8000. in browser: http://10.206.xxx.yyy:8000/polls result: same Firefox can't establish a connection 

netstat的

 $ netstat -aon Active Internet connections (servers and established) Proto Recv-Q Send-Q Local Address Foreign Address State Timer tcp6 0 0 :::80 :::* LISTEN off (0.00/0/0) # I don't know what this means exactly and why I can't see this server from the browser 

任何想法,为什么它不工作?

如果使用vanilla runserver则连接到本地主机(127.0.0.1)。 这意味着您只能在实际的服务器实例中访问它。 为了让它连接到它的实际IP,你可以使用:

 $ python manage.py runserver 0.0.0.0:8000 

如果你喜欢,你可以使用另一个端口,但是如果你想在端口80上连接它,你将需要sudo:

 $ sudo python manage.py runserver 0.0.0.0:80 

注意:这可能不是很明显,以防万一: 0.0.0.0部分是有意的。 这意味着本质上连接到服务器分配的IP地址。 您可以使用实际的IP地址,但我发现这更容易:您不必记住或查找服务器的IP。

FWIW:当你有一个用于桥接networking的虚拟机设置时,这对于浏览器testing也很出色。 虚拟机通过桥接networking在局域网上获得自己的IP。 因此,例如,在Windows主机上运行Linux客户机,可以在VM中以这种方式加载runserver,然后在Windows主机上打开IE,并将其指向虚拟机的IP地址。

看来你正在使用BitNami DjangoStack 。 包含在堆栈中的Apache服务器应该正在运行,这就是为什么你不能在80端口启动服务器。如果你只是开发,你想使用django服务器,你可以停止Apache服务器。

 sudo /opt/bitnami/ctlscript.sh stop apache 

另外请注意,如果你想使用不同的端口,你可能需要在你的亚马逊安全组中打开它。

答案都是对的,但我认为你的整个做法并不理想。 django开发服务器对某些事情有好处,但实际上在云中耗尽并不一定是其中之一。 我会build议实际上只使用Apache,其中bitnami djangostack使你很容易。

所以你要做同样的事情,直到你运行runserver,在这一点上,你会编辑具有django的东西,我认为这是所谓的django.conf适当的Apacheconfiguration文件:

 WSGIScriptAlias /django “/opt/bitnami/apps/django/conf/django.wsgi” 

或者什么是对的(这可能是正确的)。

然后去编辑该文件,以确保事情指向正确的地方:

 sys.path.append('/opt/bitnami/') sys.path.append('/opt/bitnami/myproject') os.environ['DJANGO_SETTINGS_MODULE'] = 'myproject.settings' 

然后重新启动Apache。 现在当你点击80端口时,它应该调用你的django代码。 你可以做的一件事是确保在settings.py文件中将DEBUG设置为True,这样你就可以用调用django和实际的django代码或configuration的问题来消除问题。