Redirect Foreign Domain to Error404

I been really bothered recently by one of the new site that I'm currently building while waiting for the new domain name servers to propagate on Route 53.

I have spent couple of days building up quite some amount of contents from one of the Professor I work with.


After all the efforts and while the domain name is still not properly resolved, I began to get impatient and worried.

So I went to google the website name and found my contents already indexed on Google. At the time, the website was still on a bare IP address due to the slow propagation.

And to my surprise, thietkenghean.com who has his name servers location in Vietnam has happily pointed his domain to my web server's IP.

So instead of Google recognising those contents being mine, they are now being served under this foreign domain name who never operate those servers nor owning any of its contents.

Now, I think that's stealing 😡. After much of finding out what happened (which there are very little info on this issue), I have decided to share this for just in case anyone who encounter the same problem like mine.

Below is the simple approach I have taken for a DigitalOcean droplet with Ghost and nginx installed.

The idea was to redirect the offending/foreign domain to an error 404 page using nginx.

In the terminal after you have logged in with editing privilege, change to the nginx server blocks directory.

cd /etc/nginx/sites-available

You should be seeing a default and ghost file located inside this directory, where you can then edit the ghost server block.

nano ghost

add in the server block below and replace the domain name after the server_name section to match the offending domain on your sites.

server {  
    listen 80;

    server_name thietkenghean.com www.thietkenghean.com *.thietkenghean.com; # Replace with the offending domain name.

    root /usr/share/nginx/html;

    error_page 404 /404.html;

    location / {
        return 404;
    }

    location = /404.html {
        internal;
    }
}

When you're done, you can save the file by using Ctrl + x to close the file where it would ask if you want to save the changes. Simply press Y for Yes and confirm the filename.

You will then exit the nano editor and issue a service nginx restart command to restart nginx.

Now go back to the browser and try accessing that offending domain, it should send the user to a 404 error.


I'm writing this as note keeping for myself and in the hope that it would help someone else. If any parts of the above was not ideally correct do tweet me @flikteoh and share with me the better solutions.