Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I access my django app running on Amazon ec2?

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

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

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.

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!

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!

like image 312
kakka1234 Avatar asked Dec 25 '22 17:12

kakka1234


1 Answers

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

So either close port 80 and open port 8000 from the security group, or run your app on port 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.

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

  1. Run a pre-configured AMI image for django (like this one from 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).

like image 188
Burhan Khalid Avatar answered Dec 28 '22 10:12

Burhan Khalid