Naveen
Naveen

Reputation: 677

Access Django App on AWS ec2 host

This issue might seem very trivial but please try to suggest a solution for this if possible. I have deployed a django App on AWS ec2 host and I am able to run the following command successfully.

(venv)[ec2-user@ip-xxx-xx-xx-xx abc]$ python manage.py runserver
Performing system checks...

System check identified no issues (0 silenced).
January 03, 2016 - 13:15:31
Django version 1.7.1, using settings 'abc.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.

But I am not able to access http://127.0.0.1:8000/ from the browser. On googling it's suggesting to use nginx or gunicorn. I am not sure if nginx, gunicorn etc. are to be used for this.

Can someone please let me know how can this be accessed from browser ? Thanks,

Upvotes: 3

Views: 5617

Answers (3)

Gihan Gamage
Gihan Gamage

Reputation: 3364

In order to archive this all you need to do 3 simple steps.

  1. Go to the EC2 Console and open up the security group of your instance. go to inbound tab. click Edit and then press add rule...add entry with type of Custom TCP Rule and port 8000..
  2. Go to your Django project,your app and open up the settings.py script. List your IPv4 address in the allowed_hosts section.. Ex : ALLOWED_HOSTS=['public IPv4']'
  3. Now in the console run command python manage.py runserver 0.0.0.0:8000...

Open any web browser(from any device) and open the link 'public IPv4':8000

No need any app servers like Apache, NginX..

Upvotes: 5

Ivan Semochkin
Ivan Semochkin

Reputation: 8897

You need to open HTTP port in AWS instance menu.(all ports except ssh closed in AWS)
Go to your console.aws.amazon.com, then pick your instance and go to last menu item "security groups". It lauch wizard, click on "Inbound" in bottom menu, then "edit", and add HTTP or any port what you want :)
And be sure you using your public AWS IP, to open in browser

Add some screen for you, hope it help:
enter image description here

enter image description here

enter image description here

Upvotes: 12

Kane Blueriver
Kane Blueriver

Reputation: 4268

@Baterson is right. You should open port 8000 for your server first.

Official document is here: http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/authorizing-access-to-an-instance.html . It is highly detailed.

Upvotes: 0

Related Questions