LCWD LogoLearn Code With DurgeshLCWD
HomeCoursesHandbooksBlogsContact
About LCWDAbout Durgesh Tiwari
Flex Box Hero
LearnCodeWithDurgesh Logo

Learn Code With Durgesh

Offering free & premium coding courses to lakhs of students via YouTube and our platform.

Explore

  • About Us
  • Courses
  • Blog
  • Contact
  • FlexBox Game

Legal

  • Privacy Policy
  • Terms & Conditions
  • Refund Policy
  • Support

Contact

  • 📞 +91-9839466732
  • [email protected]
  • Substring Technologies, 633/D/P256 B R Dubey Enclave Dhanwa Deva Road Matiyari Chinhat, Lucknow, UP, INDIA 226028
© 2025 Made with ❤️ by Substring Technologies. All rights reserved.
Deploying Django using Ngnix and Gunicorn on Ubuntu

Deploying Django using Ngnix and Gunicorn on Ubuntu

By durgeshkumar8896 • Sun Jul 07 2024

Deploying Django using Ngnix and Gunicorn on Ubuntu

Deploying Django using Ngnix and Gunicorn on Ubuntu

learn code with durgesh images

First of all,  I am going to install MySQL database because we are using it in our project

Installing MySQL 

Update 

sudo apt update

Then install the mysql-server package:

sudo apt install mysql-server

Ensure that the server is running using the systemctl start command:

sudo systemctl start mysql.service

Configure Mysql

mysql_secure_installation

We are  not going to use root user , so we will create new user 

Creating New MySQL User

mysql -u root -p

CREATE USER 'username'@'host' IDENTIFIED BY 'password';

GRANT ALL PRIVILEGES ON *.* TO ‘user’@'host’;

FLUSH PRIVILEGES;

exit

Now you can login with your username and password using command:

mysql -u username -p 

 

Deploying Django with Nginx and Guicorn

Install python, pip and Ngnix 

sudo apt install python3-pip python3-dev nginx

Creating a python virtual environment 

sudo apt install virtualenv

Create project folder 

cd /
mkdir projects
cd projects

I have created projects folder at root.

Create and activate the virtual env

virtual env 
source env/bin/activate

Upload the django project  

I am going to clone the project from github as i have project on github.

git clone https://github.com/DurgeshCoder/lcwd-back.git

cd lcwd-back

pip3 install -r requirements.txt

 

If you have any migrations then migrate and also put the correct database details in settings.py file

python3 manage.py migrate

Now test application is running on development server or not

python3 manage.py runserver 0.0.0.0:8000

Check using IP and Port 8000.

Now use Gunicorn 

Let's create a system socket file for gunicorn now:

sudo vim /etc/systemd/system/gunicorn.socket

Paste the contents below and save the file

Description=gunicorn socket

[Socket]
ListenStream=/run/gunicorn.sock

[Install]
WantedBy=sockets.target```

Next, we will create a service file for gunicorn

sudo vim /etc/systemd/system/gunicorn.service 

Paste the contents below inside this file:

Description=gunicorn daemon
Requires=gunicorn.socket
After=network.target

[Service]
User=ubuntu
Group=www-data
WorkingDirectory=/projects/lcwd-back
ExecStart=/projecgs/env/bin/gunicorn \
          --access-logfile - \
          --workers 3 \
          --bind unix:/run/gunicorn.sock \
          textutils.wsgi:application

[Install]
WantedBy=multi-user.target```

Lets now start and enable the gunicorn socket

sudo systemctl start gunicorn.socket
sudo systemctl enable gunicorn.socket

Configurations of Ngnix

sudo vim /etc/nginx/sites-available/lcwd

Paste the below contents inside the file created

listen 80;
server_name www.learncodewithdurgesh.com;

    location = /favicon.ico { access_log off; log_not_found off; }
    location /static/ {
        root /projects/lcwd-back;
    }

    location /media/ {
        root /projects/lcwd-back;
    }

    location / {
        include proxy_params;
        proxy_pass http://unix:/run/gunicorn.sock;
    }

}

Activate the configuration using the following command:

sudo ln -s /etc/nginx/sites-available/lcwd /etc/nginx/sites-enabled/ 

Restart nginx and allow the changes to take place.

sudo systemctl restart nginx

Now check on port 80 your site will run.

Share this article ...

💬WhatsApp📘Facebook💼LinkedIn🐦X

Trending Blogs...

Top 10 CSS Tips That Will Instantly Improve Your Design Skills

Top 10 CSS Tips That Will Instantly Improve Your Design Skills

Before writing CSS, know how it connects with HTML and why using external stylesheets is best.

Best Investment Apps in India (2025): Invest Smart, Grow Faster

Best Investment Apps in India (2025): Invest Smart, Grow Faster

Investing today has become easier than ever — thanks to powerful mobile apps that put the entire stock market, mutual funds, and digital assets right in your pocket .

Top 10 High-Paying Skills to Learn in 2025

Top 10 High-Paying Skills to Learn in 2025

Hey there! If you’re feeling the pressure of keeping up with today’s crazy-fast job market, you’re not alone. AI, automation, and digital transformation are flipping industries upside down, and the skills that used to land you a solid gig might not cut it anymore.

iphone 17 Launch 2025: Features, Price in India, Pros & Cons

iphone 17 Launch 2025: Features, Price in India, Pros & Cons

Apple has officially unveiled the **iPhone 17 series** on **September 9, 2025**, at its **“Awe Dropping” event**. The lineup includes **iPhone 17, iPhone 17 Air, iPhone 17 Pro, and iPhone 17 Pro Max**. With **120 Hz displays across all models, ultra-thin design, A19 chips, and camera upgrades**, Apple is raising the bar again.

Async/Await vs Promises in JavaScript: Which Should You Use?

Async/Await vs Promises in JavaScript: Which Should You Use?

Asynchronous programming is one of the most important topics in modern JavaScript development. Whether you’re building a web app, mobile application, or integrating APIs, you’ll often deal with operations that don’t finish instantly, such as fetching data or reading files.

AI: Boon or Curse? Advantages & Disadvantages Explained

AI: Boon or Curse? Advantages & Disadvantages Explained

Artificial Intelligence (AI) is no longer just a concept of the future—it is already shaping our present. From asking Alexa or Siri to play music, using Google Maps for directions, or experiencing personalized recommendations on Netflix, AI has become a part of our everyday life.

Share this article ...

💬WhatsApp📘Facebook💼LinkedIn🐦X