Deploying Scalable Django Applications with Gunicorn and NGINX: A Guide by Code with Harry

Posted by

How to Deploy Scalable Django Apps Using Gunicorn and NGINX | Code with Harry

How to Deploy Scalable Django Apps Using Gunicorn and NGINX | Code with Harry

Deploying Django apps is a crucial step in the development process. In this article, we will discuss how to deploy scalable Django apps using Gunicorn and NGINX.

Step 1: Install Gunicorn

To start, you will need to install Gunicorn, a WSGI server for Python web applications. You can install Gunicorn using pip:

pip install gunicorn

Step 2: Run Gunicorn

To run your Django app using Gunicorn, navigate to your project directory and run the following command:

gunicorn --bind 0.0.0.0:8000 myproject.wsgi

Step 3: Install NGINX

Next, you will need to install NGINX, a high-performance web server and reverse proxy. You can install NGINX using apt-get:

sudo apt-get install nginx

Step 4: Configure NGINX

After installing NGINX, you will need to configure it to reverse proxy requests to Gunicorn. Create a new NGINX configuration file in the /etc/nginx/sites-available directory with the following content:


server {
listen 80;
server_name example.com;

location / {
proxy_pass http://127.0.0.1:8000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}

After creating the configuration file, activate it by creating a symbolic link to the /etc/nginx/sites-enabled directory:

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

Step 5: Restart NGINX

Finally, restart NGINX to apply the changes:

sudo service nginx restart

Your Django app should now be deployed and accessible at your server’s IP address or domain name. Congratulations on successfully deploying your scalable Django app using Gunicorn and NGINX!

0 0 votes
Article Rating
8 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
@devendrakanojiya
6 months ago

👍 harry sir

@imadlatch7206
6 months ago

The video title is wrong, your title is Django Apps Using "uWSGI" and NGINX not "Gunicorn"

@parasthakur3922
6 months ago

Tu b

@PravenKumar-es1vd
6 months ago

New. Ringtone

@skroyeducation2166
6 months ago

How can I deploy kivy app in exe or apk I have already tried it using Collab and pyinstaller but these methods produces errors

@crimpflyer7073
6 months ago

English language samj me nahi aa rahi 😂

@zainabjaved352
6 months ago

You was born to Code..
You was born to Serve
Love from Pakistan ❤️
You are a great teacher and guider to me✨🥺

@_tylerkinney
6 months ago

Thanks! This was really helpful and informative!❤