[Answered ]-Hosting Django App on AWS EC2 Host

2👍

Nginx used for static files. For django project you need to install application server like uwsgi or gunicorn
It will work by this logic:
user <-> nginx <-> app_server <-> django
Here is guide for nginx + gunicorn + django
http://tutos.readthedocs.org/en/latest/source/ndg.html

UPD for comments
some config for you, maybe it helps.
Nginx

server {
listen 80;
server_name your_public_ip;
access_log  /var/log/nginx/your_nginx.log;

location /media  {
    alias /home/ubuntu/Project/project/media;     
    #It is path to your media, you can check this by 'pwd' command
}

location /static {
    alias /home/ubuntu/Project/project/static_root;
}
    #same
location / {
    proxy_pass http://127.0.0.1:8000;
    proxy_set_header Host $server_name;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}

install gunicorn and make it autostart by supervisor
sudo apt-get install supervisor
open file
sudo vim /etc/supervisor/conf.d/project.conf
and write this config

[program:project] #by this name you will call supervisor
command=/home/ubuntu/venv/bin/gunicorn --bind localhost:8000 project.wsgi:application    
enviroment=PYTHONPATH=/home/ubuntu/venv/bin    #path to virtualenv
directory=/home/ubuntu/project_folder/project  #you path to project
user=ubuntu  #your user

start it
sudo supervisorctl start project

also comand for supervisor:
sudo supervisorctl reload
sudo supervisorctl status
sudo supervisorctl reread
sudo supervisorctl update

Leave a comment