Deploy django app with subdomain

Posted August 25, 2016 7.7k views

I am going to deploy a django app with nginx and gunicorn. The site ( has language subdomains (fr.example etc), which is managed directly by my django app (it detects the subdomains and sets the proper language). So this gona be one app for several subdomains.
So I have questions about settings:

  • What to write in Networking panel in DO?
  • How to configure Nginx?

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
1 answer

The following solution will work as long as you are not hosting separate sites that also use a subdomain on the same server and all requests for * that come to that server are expected to be served by your django app.

In the examples below should be replaced with your IP address and with your domain name

What to write in Networking panel in DO?

Create the following DNS records:

@   A
*  CNAME @

The first record points your domain ( to your droplet’s IP address. This record handles any request for without a subdomain.
The second record says that any subdomain name should point to the same address as the domain without a subdomain. In our system this wildcard should be processed after any other defined subdomain records and act as a catch all. This means that existing records for things like can remain and should not pose a problem.

How to configure Nginx?

If this is the only site configured in nginx and has a default_server setting attached to it’s listen directive you wont have to make any changes at all since this will pass all requests on to your django application. If you have more than one site defined you’ll need to make a very minor configuration change. Open your site’s configuration file in /etc/nginx/sites-enabled/ and inside the server{} block you should see a server_name directive. Setting this to instead of is all that is needed.