DEV Community

Cover image for How to deploy Django Web App on Ubuntu AWS EC2 with nginx Configuration
Aman Sharma
Aman Sharma

Posted on

4 3

How to deploy Django Web App on Ubuntu AWS EC2 with nginx Configuration

Hey you can deploy your website by following this link.

Here's a Youtube Video link

https://youtu.be/L8-8b8BBR5U

Just follow the exact steps and you'll do it within 30 minutes.

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install python3-venv
python3 -m venv venv
source venv/bin/activate
pip3 install django
git clone 'Your repo'
cd /yourRepo
pip3 install gunicorn
sudo apt-get install -y nginx
gunicorn --bind 0.0.0.0:8000 aoo.wsgi:application { to view the running app }

sudo apt-get install supervisor
cd /etc/supervisor/conf.d
sudo touch gunicorn.conf
data to enter -

[program:gunicorn]
directory=/home/ubuntu/resume/djangoResume
command=/home/ubuntu/venv/bin/gunicorn --workers 3 --bind unix:/home/ubuntu/resume/app.sock djangoResume.wsgi:application

autostart=true
autorestart=true
stderr_logfile=/var/log/gunicorn/gunicorn.err.log
stdout_logfile=/var/log/gunicorn/gunicorn.out.log

[group:guni]
programs:gunicorn

sudo mkdir /var/log/gunicorn
sudo supervisorctl update
sudo supervisorctl reread

cd /etc/nginx/sites-available
sudo touch django.conf
paste below code there-

server {
server_name yourIp;
server_name www.yourDomain;
server_name yourDomain;

location / {
        include proxy_params;
        proxy_pass http://unix:/home/ubuntu/path/app.sock;

}

 location /static/ {
        autoindex on;
        alias /home/ubuntu/path/static/;
        }
location /media/ {
        autoindex on;
        alias /home/ubuntu/path/media/;

sudo ln django.conf /etc/nginx/sites-enabled/
sudo nginx -t

►Website (created using Django) - https://www.amannvl.me
►Facebook - https://www.facebook.com/amannvl
►Instagram - https://www.instagram.com/amannvl/
►Twitter - https://twitter.com/amannvl

Sentry blog image

How I fixed 20 seconds of lag for every user in just 20 minutes.

Our AI agent was running 10-20 seconds slower than it should, impacting both our own developers and our early adopters. See how I used Sentry Profiling to fix it in record time.

Read more

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay