NGINIX Security / Redirect Help

I have discovered that – for some reason – another domain name is pointing to my website. I’m unsure why this is, but I assume it’s malicious and would like to prevent this from happening. It seems like the best fix is a 301 redirect but I’m not used to nginx and haven’t had any success trying to figure this out on my own.

For instance, if my website is “coolblog.com,” then “otherblog.com” is pointing to “coolblog.com”.

To pseudocode a fix, I believe I need something in the nginx config file to the effect of:

server {
(if incoming traffic != from coolblog.com) {
301 redirect to https://coolblog.com/$uri}
}

I do not know how to implement this. Any tips?

Info:
Ubuntu 20.04
Ghost 5.42.0

Update your Nginx Configuration something like that…

sudo nano /etc/nginx/sites-available/default

Now you can add a new server block to catch any unauthorized traffic and redirect it to your main domain coolblog.com

Here’s an example set of script…

server {
    listen 80 default_server;
    server_name _;

    if ($host !~ ^(coolblog\.com)$ ) {
        return 301 https://coolblog.com$request_uri;
    }

    # Other configuration directives go here...
}

Save it and test it 

1 Like

before applying above changes it’s a good practice to test the Nginx configuration to make sure there are no syntax errors.

sudo nginx -t

once done check manually use browser developer tools to inspect network requests and redirects or use any online tool like https://redirectchecker.com/ This can help you to get Bulk url detail redirection chain and its status code.

1 Like