Deploy django app with subdomain

Hello! 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?

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

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.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

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.