Question

How to assign a subdomain to my Django project on Digital ocean Droplet?

We already have a website called X.com. Now i am building a Django App on a Digital ocean Droplet. i am able to access it using the ip-address. But we want to have it called reporting.X.com for sharing it with our users. On my domain providers, I already added an A record like the below Host- reporting Type - A Content - <ip-address> of digital ocean droplet

However, I keep getting the following message when i try to access reporting.X.com.

Welcome to nginx!
If you see this page, the nginx web server is successfully installed and working. Further configuration is required.

For online documentation and support please refer to nginx.org.
Commercial support is available at nginx.com.

Thank you for using 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.

Okay I have resolved the issue. So I will answer this for future reference of other people.

You need to check 2 important places.

  1. /etc/nginx/sites-enabled/<your_project>

If you want your django app with just the subdomain, your project file in sites-enabled should look like below.

server {
    listen 80;
    server_name <ip-address> .X.com;

    location = /favicon.ico { access_log off; log_not_found off; }
    location /static/ {
        root /home/eleena/reporting_app;
    }

    location / {
        include proxy_params;
        proxy_pass http://unix:/home/eleena/reporting_app.sock;
    }

The dot in front of X.com is not a typo. This basically says any sub domain for X.com.

  1. settings.py file in Django App

You have to set ALLOWED_HOSTS this way. ALLOWED_HOSTS = ['ip-address', '.X.com'] Again X.com is preceded with a dot.

In the question, I already mentioned that I created an A record with following details.

Host- reporting
Type - A
Content - <ip-address> of digital ocean droplet

After this, restart your nginx server. sudo systemctl restart nginx

Now, theoretically it should work. But if it doesn’t (as it didn’t for me), you have to shutdown and restart your droplet.

sudo shutdown -r now

My Django app started to work after this activity. Hope it helps.

The good news is your A record is pointing to your Droplet and is resolving correctly.

I assume you have created a Nginx conf for your subdomain and set the server_name property to reporting.x.com?

Restart Nginx after setting your conf by running:

systemctl restart nginx