Report this

What is the reason for this report?

Prolem: subdomain redirect to maindomain

Posted on August 25, 2020

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



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.

@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 @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

To be clarify, when i go to sub.example.com it should shows the index.html I created, but it redirect me to sub.example.com/users/login and shows the login page for user on my main domain.

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.