Deploy multiple django apps on a single machine

Posted on : 1st Sep 2020

This post describes how you can deploy multiple django applications on a single linux machine. For this tutorial we will be deploying django apps with gunicorn sock files and we will use nginx for reverse proxy.

Pre-requisite :

A running gunicorn service for your django app, with a .sock file.

Process :

The solution is quite simple, if both of your applications are for two different domain names you need to create two NGINX server blocks. Similarily, if your applications are under same domain name but require to run on different paths you need to create two NGINX location blocks within same server block.

Below is a sample code for two django apps on two different domain names.

server {
    server_name example1.com www.example1.com;
    location / {
        include proxy_params;
        proxy_pass http://unix:/home/sith/project/project.sock;
    }
}

and another server block,

server {
    server_name example2.com www.example2.com;
    location / {
        include proxy_params;
        proxy_pass http://unix:/home/sith/project/project.sock;
    }
}

Make sure you make a symbolic link of your config on sites-enabled directory afterwards. Cheers.

© 2021, All Rights Reserved · Vipin Joshi