how do i host multiple django appliction in same droplet with different domain names ?

May 28, 2015 576 views
Django Applications Ubuntu

Is there any tutorial to host multiple django application in one droplet with different host names ?

1 Answer

In order to have more than one Django app running on one Droplet, you'll need to set up something like Nginx as a reverse proxy to direct requests to the correct app. By setting the server_name directive in each of your server blocks, Nginx will know what to serve.

Here's a simplified example:

upstream app_server_one {
    server 127.0.0.1:9000 fail_timeout=0;
}

upstream app_server_two {
    server 127.0.0.1:7000 fail_timeout=0;
}

server {
    listen 80;
    server_name app1.example.com;

   # [snip...]

    location / {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_redirect off;
        proxy_pass http://app_server_one;
    }
}

server {
    listen 80;
    server_name app2.example.com;

   # [snip...]

    location / {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_redirect off;
        proxy_pass http://app_server_two;
    }
}

In the example, requests to app1.example.com will serve a Django app listening on port 9000 and app2.example.com will serve the app listening on port 7000.

You can get more info on how to use Nginx server block in this tutorial:

And on using Django with Nginx:

by Justin Ellingwood
Nginx is an incredibly powerful web server and reverse proxy. In this guide, we'll discuss how to set up server blocks on Ubuntu 14.04 in order to server multiple domains from a single server.
Have another answer? Share your knowledge.