Question

Prolem: subdomain redirect to maindomain

Hi, I’m creating a new subdomain (sub.example.com) on the same droplet as my main domain (example.com). I’m able to ping the subdomain and check DNS (https://www.digitalocean.com/community/tools/dns). However, whenever I come to sub.example.com, it still redirect me to my main domain’s content (the bar still shows sub.example.com). My main domain is a wordpress website. My sub.example.com.conf on etc/nginx/sites-available: server { listen 80; root /var/www/sub.example.com; index index.html index.htm index.nginx-debian.html; server_name sub.example.com www.sub.example.com; location / { try_files $uri $uri/ =404; } }

Hosts file: myip sub.example.com


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.

HI @gnohpcntt,

Apart from the other good answers, can you verify the subdomain is actually a blank website or is it a WordPress as well? I’m asking as it’s possible you are using either the same database for your subdomain or having your home url set to your main domain. Check that just in case as well.

Regards, KFSys

@gnohpcntt here is your checklist:

  1. Recheck your hosts file to ensure that sub.example.com point to the actual IP of your droplet.
  2. Your Nginx configuration file looks good. You put it in the /etc/nginx/sites-available folder. So don’t forget to create a symlink to it in the /etc/nginx/sites-enabled folder too.
  3. Reload Nginx to apply changes.

You should read Step Four: Enable your Server Blocks and Restart Nginx for more details.

Hi! That’s good you’ve verified that the DNS is resolving correctly. It seems you are on the right track with a separate nginx conf file for your sub-domain - did you restart nginx after making that file? You probably did but just in case ;)

I also like to try the new DNS / webhost config from multiple browsers and devices - the browsers today will cache the darnedest things. You could do this easily with an incognito window on your workstation and on your phone if thats available. This will verify that the problem is on the server and not just on your computer.

Otherwise, it sounds like your main domain web server (nginx) config might be overriding the subdomain config… here’s an article in the DO knowledgebase with some examples - if you have not already, please review what you have against what is presented in this tutorial:

https://www.digitalocean.com/community/tutorials/how-to-set-up-nginx-server-blocks-virtual-hosts-on-ubuntu-16-04

If you’re still stuck, please share a version of your main domain configuration so we can look for possible conflicts.

Hope this helps and good luck!