BigCloudy KnowledgeBase BigCloudy KnowledgeBase
  • Cloud Hosting
    • cPanel Hosting
    • Laravel Hosting
    • Node.js Hosting
    • Magento Hosting
    • Django Hosting
    • Reseller/Agency Hosting
    • SSL Certificates
  • WordPress
    • WordPress Hosting
    • WooCommerce Hosting
  • VPS & Dedicated Server
    • Linux VPS Hosting
    • Windows VPS
    • Forex VPS Hosting
    • SEO VPS Hosting
    • n8n VPS Hosting
    • Dedicated Servers
  • AI Website Builder
Log in
BigCloudy KnowledgeBase BigCloudy KnowledgeBase
Log in
BigCloudy KnowledgeBase BigCloudy KnowledgeBase
  • Cloud Hosting
    • cPanel Hosting
    • Laravel Hosting
    • Node.js Hosting
    • Magento Hosting
    • Django Hosting
    • Reseller/Agency Hosting
    • SSL Certificates
  • WordPress
    • WordPress Hosting
    • WooCommerce Hosting
  • VPS & Dedicated Server
    • Linux VPS Hosting
    • Windows VPS
    • Forex VPS Hosting
    • SEO VPS Hosting
    • n8n VPS Hosting
    • Dedicated Servers
  • AI Website Builder
creativeleaf
loading
Popular Searches
  • wordpress
  • how do i add new domains or subdomains in plesk?
  1. Home
  2. Framework
  3. Python
  4. How to set up Gunicorn and Nginx for Django?
Updated on February 9, 2026
Framework
  • Folder icon closed Folder open iconNode.Js
    • How do I deploy a Node.js app on your hosting?
    • What Node.js Versions Are Supported?
    • How Do I Configure Environment Variables in Shared Hosting?
    • Can I Run Multiple Node.js Apps Under One Account?
    • How to fix “503 Service Unavailable” in Node.js hosting?
  • Folder icon closed Folder open iconPython
    • Do You Support Python and Django Applications?
    • How Do I Deploy a Django App on Your VPS or Shared Server?
    • How to set up Gunicorn and Nginx for Django?
    • How Do I Manage Static and Media Files in Django Hosting?
    • Can I use virtual environments with Django hosting?
  • Folder icon closed Folder open iconLaravel
    • How to Deploy a Laravel Project on BigCloudy Shared Hosting ?
    • How Do I Set Up .env and Manage Environment Variables in Laravel?
    • Is SSH access available for running artisan commands?
    • How to configure queues and cron jobs in Laravel hosting?
    • Can I connect Laravel with a remote MySQL server?

How to set up Gunicorn and Nginx for Django?

Introduction

Django is a high-level Python web framework that allows rapid development of secure and scalable websites. It is an excellent choice when you need more control and dedicated resources, which is why it works especially well on VPS Hosting.

In this guide, you will learn how to deploy a Django application using Gunicorn and Nginx on a VPS hosting environment. This method is ideal for production deployments that prioritize performance, security, and flexibility.

You will set up a virtual environment, install Django and Gunicorn, and configure Nginx to serve your Django application efficiently on your VPS. This approach gives you full server-level control and is recommended for serious or growing Django projects.

Note: You’ll need root or sudo access to your VPS to follow these steps.

Prerequisites

Before you begin:

  • A VPS with Ubuntu 22.04 or later.
  • Root or sudo user access.
  • A domain name (optional but recommended).
  • Basic familiarity with Linux commands.

Step 1 – Installing Python and Nginx

First, update your server packages:

Then install Python, Pip, and Nginx:

Tip: Make sure Nginx is running:

				
					# sudo apt update

# sudo apt install python3-pip python3-dev nginx

#sudo systemctl status nginx
				
			

Step 2 – Creating a Python Virtual Environment

Install the virtual environment package:

Create your project directory:

Create and activate a virtual environment:

Note: Once activated, your prompt will change to (env), confirming the environment is active.

				
					# sudo pip3 install virtualenv

# mkdir ~/projectdir
# cd ~/projectdir

# virtualenv env
# source env/bin/activate
				
			

Step 3 – Installing Django and Gunicorn

Install Django and Gunicorn in your virtual environment:

You can verify the installation:

				
					# pip install django gunicorn

# django-admin --version 

# gunicorn --version
				
			

Step 4 – Setting Up Your Django Project

You can copy your existing Django project into ~/projectdir/ — or create a new one:

Open the project’s settings file:

Update the ALLOWED_HOSTS variable:

Run database migrations:

Open port 8000 in the firewall:

Start Django’s development server to test your setup:

				
					# django-admin startproject myproject ~/projectdir

# nano ~/projectdir/myproject/settings.py

ALLOWED_HOSTS = ['your_server_ip', 'your_domain.com']

# python manage.py makemigrations 
# python manage.py migrate

# sudo ufw allow 8000
# python manage.py runserver 0.0.0.0:8000
				
			

Now visit:

http://<your-server-ip>:8000

If you see the Django welcome page, your project is working.

Step 5 – Configuring Gunicorn

Test Gunicorn’s ability to serve the application:

You can now access your Django app at:
http://<your-server-ip>:8000

Once verified, stop Gunicorn with CTRL + C.

				
					# gunicorn –bind 0.0.0.0:8000 myproject.wsgi:application
				
			

Step 6 – Creating a systemd Service for Gunicorn

To manage Gunicorn as a background service, create a systemd unit file:

				
					# sudo nano /etc/systemd/system/gunicorn.service
				
			

Add the following configuration:

				
					[Unit] 

Description=Gunicorn daemon for Django project 
After=network.target 

[Service] 

User=root Group=www-data 
WorkingDirectory=/home/username/projectdir 
ExecStart=/home/username/projectdir/env/bin/gunicorn –workers 3 –bind
unix:/home/username/projectdir/myproject.sock myproject.wsgi:application

[Install] 

WantedBy=multi-user.target
				
			

Save and close the file, then start and enable the service:

				
					# sudo systemctl start gunicorn 

# sudo systemctl enable gunicorn 

# sudo systemctl status gunicorn
				
			

Note: If you make changes, reload systemd

				
					# sudo systemctl daemon-reload
				
			

Step 7 – Configuring Nginx as a Reverse Proxy

Create an Nginx configuration file:

Add this configuration:

				
					# sudo nano /etc/nginx/sites-available/myproject
				
			
				
					server { 
listen 80; 
server_name your_domain.com your_server_ip; 
location = /favicon.ico {
access_log off; 
log_not_found off; }
location /static/ { 
root /home/username/projectdir; 
  } 
location / { 
include proxy_params; 
proxy_pass http://unix:/home/username/projectdir/myproject.sock; 
  } 
}
				
			

Add this configuration:

Enable the configuration and restart Nginx:

You can now access your Django app using your domain or IP.

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

# sudo nginx -t # sudo systemctl restart nginx
				
			

Step 8 – Enabling Firewall and Testing Setup

Allow Nginx through the firewall:

Reload UFW:

				
					# sudo ufw allow ‘Nginx Full’ 

# sudo ufw delete allow 8000

# sudo ufw reload
				
			

Now open your browser and visit:
http://your_domain.com

Your Django app should be running behind Nginx and Gunicorn.

Common Issues and Fixes

IssueCauseSolution
502 Bad GatewayGunicorn service not runningRun sudo systemctl restart gunicorn
Permission DeniedIncorrect file or folder permissionsEnsure /home/username/projectdir is owned by www-data or root
Static files not loadingMissing static configurationRun python manage.py collectstatic
Gunicorn not foundvenv path incorrect in service fileUpdate ExecStart path in gunicorn.service

Conclusion

Django applications can be deployed on both shared hosting and VPS environments using standard, well-supported setups. On shared hosting, cPanel with CloudLinux Passenger provides a managed approach that handles virtual environments and application startup with minimal configuration. This option is suitable for smaller projects and straightforward deployments.

On a VPS, using Gunicorn with Nginx offers full control over the server and application behavior. This setup is better suited for applications that require higher performance, persistent processes, or custom server configuration. In both cases, using virtual environments, matching Python and Django versions, managing static files correctly, and restarting services after changes are essential for a stable deployment.

Need Help?

If you require assistance at any point while using this guide, our Support Team is here to help:
  • email Email: support@bigcloudy.com
  • website Submit a support ticket
Confirm your purchase by clicking “Continue” button.

FAQ

Can I use this setup for multiple Django apps?

Yes, create separate Gunicorn service and Nginx config files for each app.

How can I enable HTTPS?

Install and configure Certbot for Nginx:

# sudo apt install certbot python3-certbot-nginx

# sudo certbot –nginx -d your_domain.com

What’s the advantage of using Gunicorn with Nginx?

Gunicorn serves Django efficiently, while Nginx handles static files, caching, and request load balancing.

How to restart the Gunicorn service?

# sudo systemctl restart gunicorn

How can I check Gunicorn logs?

# sudo journalctl -u gunicorn

Still stuck? How can we help?

How can we help?

Was this page helpful? Yes No

Powered By BigCloudy

Cloud Hosting

cPanel Hosting
Laravel Hosting
Node.js Hosting
Magento Hosting
Django Hosting
WordPress Hosting
WooCommerce Hosting
Reseller / Agency Hosting

Cloud VPS & Server

Linux VPS Hosting
Windows VPS Hosting
Forex VPS Hosting
SEO VPS Hosting
n8n VPS Hosting
Dedicated Server

Addons

Domain
SSL Certificates
AI Website Builder
Affiliate Program

Company

About Us
Contact Us
Blog
Knowledge Base
Sitemap
Status

Legal

Privacy Policy
Terms of Service
Refund Policy
Affiliate TOS

Follow Us

Facebook X-twitter Instagram Linkedin

Copyright Ⓒ 2026 BigCloudy Internt Services Pvt. Ltd. All Rights Reserved