Report this

What is the reason for this report?

Django not working with domain but working when accessed by server ip address?

Posted on July 17, 2020

I recently created a droplet.When i accessed the django project by droplet ip address it works fine but when i access it using domain (SaporaSocial), default nginx page shows. My allowed host are:-

ALLOWED_HOSTS=['server-ip-address','www.saporasocial.me','.saporasocial.me','saporasocial.me']


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!

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.

I am also having this issue.

When your Django project works fine with the server’s IP address but not with the domain name, and you’re seeing the default Nginx page when accessing via the domain, it usually indicates an issue with your Nginx configuration. The Nginx server block (virtual host) for your domain might not be correctly set up or may not be pointing to your Django application. Here are steps to troubleshoot and resolve this issue:

1. Check Nginx Server Block Configuration

Ensure you have an Nginx server block for your domain that points to your Django application. The configuration should look something like this (adjust paths and details as per your setup):

server {
    listen 80;
    server_name saporasocial.me www.saporasocial.me;

    location / {
        proxy_pass http://127.0.0.1:8000;  # Point to the Django server
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }

    # other configuration...
}

This configuration assumes your Django app is running on localhost (127.0.0.1) and port 8000. Adjust the proxy_pass directive to point to where your Django app is running.

2. Check for Active Configuration

Ensure that the correct server block file is linked in the /etc/nginx/sites-enabled directory. You can do this by creating a symbolic link from the sites-available directory:

sudo ln -s /etc/nginx/sites-available/my_django_project /etc/nginx/sites-enabled/

Replace my_django_project with the name of your configuration file.

3. Check Nginx for Syntax Errors

Run the following command to test your Nginx configuration for syntax errors:

sudo nginx -t

4. Restart Nginx

If everything is correct, restart Nginx to apply changes:

sudo systemctl restart nginx

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.