Django NGINX configuration with DNS


I used the one click django install to create a droplet for my blog. I have succesfully gotten the site to run, and it loads well via the the IP Address ( However, when I use my domain name (, I get a Bad Request (400) error. I purchased the domain from namecheap and redirected it to use the DO nameservers. I set it to @ for the ip address. I was thinking it was a DNS propagation issue, but whois lookups for the domain shows the digitalocean nameservers. Pinging the domain name works. Domain lookups reveal the correct IP, but I still can’t visit the site from the domain name.

I’ve configured my allowed hosts [“*”] in to see if I can get anything to work. Here’s the relevant part of my NGINX settings: Could the root, index, upstream app server be the problem? Those don’t refer to anything that I’m currently using, but since it loads fine with the IP address I didn’t think I would need to delete it.

upstream app_server {
    server fail_timeout=0;

server {
    listen 80 default_server;
    listen [::]:80 default_server ipv6only=on;

    root /usr/share/nginx/html;
    index index.html index.htm;

    client_max_body_size 4G;

    keepalive_timeout 5;

    location / {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $host;
        proxy_redirect off;
        proxy_pass http://app_server;

Any help or insights would really be appreciated!

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.

A hostname, in most standard settings, would be in the following format:

host . yourdomain . ext

So as an example, if I owned `, and I created two new Droplets and named them ocean and waves, my hostnames would be like so:

It’s best to keep them simple and straight-forward unless you’re managing a huge server-farm and are on the brink of exhausting naming options, thus being forced to move to a second . to give you more options & naming combination.

So for yours, it looks like a .me domain was attached to the hostname. Were it an actual domain you were trying to use, it would not resolve, but it would resolve to, but not alone.

You’d need to stick with a valid format as invalid hostnames & domains can cause some issues, so we’d be looking at the following for a hostname xyz using the localhost

Between the 127.0.01 and xyz.johnpham.met there is one space bar tap, or a single space. Likewise, the same is true between and and on the second line between and localhost.

After this is set, you’ll need to restart Apache, or better yet, I’d simply reboot the server entirely using:

shutdown -r now

(meaning shutdown for restart, now!)

This way the server, the networking, apache…everything gets a fresh start. If you are still getting the error, I would check the error log to see if there’s some information inside that can help uncover this issue.

Some have reported issues with using the WildCard Selector (i.e. * ), so you may want to try using the domain(s) again once the server is rebooted and back in a live, active state.

For the records: Be sure about the configuration of allowed hosts in Django Settings!

I wasted some hours to figure out that I forgot to also add the domain name there, so:

ALLOWED_HOSTS = [server_ip,,]

Did you ever figure this out? I’m having the same issue