Hello! I am going to deploy a django app with nginx and gunicorn. The site (example.com) 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:
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.
Click below to sign up and get $100 of credit to try our products over 60 days!
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
Create the following DNS records:
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.
If this is the only site configured in nginx and has a
default_server
setting attached to it’slisten
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 theserver{}
block you should see aserver_name
directive. Setting this to.example.com
instead ofexample.com
is all that is needed.