LCWD LogoLearn Code With DurgeshLCWD
HomeCoursesBlogsContact
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

image

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...

The 5 ChatGPT Prompts That Saved Me From Burnout

The 5 ChatGPT Prompts That Saved Me From Burnout

Here’s what I discovered: It wasn’t about working less. It was about working smarter. When I gave ChatGPT the right prompts, everything changed. Here are the 5 prompts that transformed my productivity:

Mastering JavaScript: Functions, Objects, Classes & Prototypes Explained Like Never Before

Mastering JavaScript: Functions, Objects, Classes & Prototypes Explained Like Never Before

If you’re learning JavaScript, you’ve probably heard terms like functions, objects, classes, constructors, inheritance, and prototypes being thrown around. But what do they really mean? And why are they so important in JavaScript? In this blog, we’ll break down these concepts step by step, with clear explanations, examples, comparisons, and diagrams. By the end, you’ll have a solid understanding of how these features work together — and why they are the backbone of modern JavaScript.

Google Tools for College Students to boost Productivity

Google Tools for College Students to boost Productivity

College life can feel like a roller coaster — assignments, exams, group projects, internships, and of course, trying to squeeze in a social life. The good news? You don’t have to do it all alone. Google has built a whole ecosystem of tools that can help students stay productive, organized, and even a little more stress-free. From taking notes to collaborating on projects, Google’s apps are like a digital toolkit every student should know about. Let’s explore how these tools can make your college journey smoother.

Can AI Make Our Food Safer Than Ever?

Can AI Make Our Food Safer Than Ever?

Every year, millions of people around the world get sick from eating contaminated food. The World Health Organization (WHO) estimates that more than 600 million people fall ill annually, and about 4.2 million die from foodborne diseases. That’s a huge number — and the scary part is, much of it comes from something we can’t even see: toxic fungi known as mycotoxins. But now, scientists may have found a way to stop this problem before it even reaches our plates. Thanks to artificial intelligence (AI) and a powerful imaging technology, our food supply could soon become safer than ever.

What is Generative AI?

What is Generative AI?

Artificial Intelligence has gone from beating humans at chess to creating human-like poetry, realistic images, and even functional code. This creative side of AI is called Generative AI — and it’s one of the most exciting areas in modern technology. But to truly understand what Generative AI means, we need to take a quick trip through history, starting with an idea that shaped all of computer science: the Turing Machine.

The Evolution of AI - From Turing to Today

The Evolution of AI - From Turing to Today

Artificial Intelligence (AI) didn’t just appear out of thin air. The chatbot answering your questions today, the recommendation system suggesting your next Netflix binge, and the self-driving cars making headlines — all of these are the result of decades of innovation, setbacks, and breakthroughs. AI’s story is one of human curiosity: a mix of science fiction dreams, brilliant engineering, and a dash of “what if machines could think?” Let’s rewind the clock and see how it all began.

HTML the Easy Way-Unlock the web

HTML the Easy Way-Unlock the web

If you’ve ever wondered how websites are built, here’s the secret: almost every webpage you see starts with HTML. Whether it’s a simple blog post, an online shop, or a social media site – HTML is the foundation.

JUnit 5 and Mockito – From Scratch to Advanced

JUnit 5 and Mockito – From Scratch to Advanced

Learn JUnit 5 & Mockito from scratch to advanced with real-time Spring Boot examples. Covers unit & integration testing, annotations, MockMvc, H2 DB, and best practices.

Modern JavaScript for Developers in 2026

Modern JavaScript for Developers in 2026

Discover the modern JavaScript features developers should know in 2026 and learn how to future-proof your skills for the evolving web landscape. This in-depth guide covers JavaScript trends 2026, emerging frameworks, and best practices to help you stay ahead in web development. Explore the top JavaScript frameworks to watch in 2026, find out what’s new in modern JS features, and see how AI-assisted JavaScript development is shaping the future. Whether you’re updating your JavaScript developer roadmap 2026 or just getting started, this article will help you master the modern JavaScript tools and techniques needed to build fast, scalable, and future-ready applications.

Debouncing in JavaScript

Debouncing in JavaScript

In this article we will learn about the debouncing . We will learn about actual real problem and how to solve this problem using js debouncing.

Maven Tutorial

Maven Tutorial

Maven is a build automation tool primarily used for Java projects. It addresses two main aspects of building software: dependency management and project build lifecycle management.

Share this article ...

💬WhatsApp📘Facebook💼LinkedIn🐦X