Beginner installing first app on EC2 bitnami stack

amazon ec2configurationdjango

Beginner question here. Its probably obvious to someone who does this stuff all the time. But I'm having difficulty setting up django running on an EC2 bitnami instance.

I setup my server and I'm able to log in. Just to test this I setup the polls example. Below are the commands I executed to get this running.

Questions:

  • What am I doing wrong here?
  • How do I get my basic polls page to show?
  • Also, is there any best practices I should follow to configure a live server?

Any step-by-steps are greatly appreciated.

—-commands—–

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

I also tried comments stated below without success.

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

Port 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

Any ideas why its not working?

Best Answer

If you use the vanilla runserver it connects to localhost (127.0.0.1). Which means you'd only be able to access it within the actual server instance. To get it to connect on it's actual IP, you can use:

$ python manage.py runserver 0.0.0.0:8000

You can use another port, if you like, but if you want to connect it on port 80, you will need to sudo:

$ sudo python manage.py runserver 0.0.0.0:80

Note: It may not be obvious, so just in case: the 0.0.0.0 part is intended. It means essentially connect to the assigned IP address for the server. You can use the actual IP address instead, but I find this easier: you don't have to remember or lookup up the server's IP.

FWIW: This also works brilliantly for browser testing when you have a VM setup for bridged networking. The VM gets its own IP on the LAN with bridged networking. So, for example, with a linux guest running on a Windows host, you can load up runserver this way in your VM, go over and open up IE on your Windows host, and point it to the VM's IP address.