The following solution will work as long as you are not hosting separate sites that also use a name.example.com subdomain on the same server and all requests for *.example.com that come to that server are expected to be served by your django app.
In the examples below 0.0.0.0 should be replaced with your IP address and example.com with your domain name
What to write in Networking panel in DO?
Create the following DNS records:
@ A 0.0.0.0
* CNAME @
The first record points your domain (example.com) to your droplet’s IP address. This record handles any request for example.com 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 mail.example.com 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 .example.com
instead of example.com
is all that is needed.