Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run Django in development on EC2 so that it is accessible to the internet?

I have Django app. It's running on an EC2. The EC2 has a private IP address and an elastic public IP address.

I want the web app to be available locally as well as Developer's IP address which is outside the network.

Let's define these three IP addresses as:

EC2_PRIVATE_IP
EC2_PUBLIC_IP
DEVELOPER_IP

So what I did was ran on the EC2:

python manage.py runserver 0.0.0.0:8000

Went into my EC2 security settings, and opened up inbound and outbound port 8000 to DEVELOPER_IP.

Then asked Developer to go to the EC2_PUBLIC_IP address on his browser.

Unfortunately that doesn't work as he gets the error:

Gateway Timeout: can't connect to remote host

Update #1

I previously tried:

python manage.py runserver {EC2_PUBLIC_IP}:8000

But I got the error:

Error: That IP address can't be assigned-to.
like image 356
JPN Avatar asked May 13 '15 14:05

JPN


1 Answers

The server should be started with below url

python manage.py runserver 0.0.0.0:8000

In EC2 security settings add following in INBOUND settings

HTTP TCP 8000 0.0.0.0/0

Then you should be accessing this machine with URL

http://EC2_PUBLIC_IP:8000

If you want to access the url as

http://EC2_PUBLIC_IP

then run your webserver on port 80 and accordingly change the EC2 security settings.

like image 192
anuragal Avatar answered Nov 15 '22 08:11

anuragal