0

I have bought multiple domain names for my website. Right now, I redirect these parked domains (the domains pointing to my nginx ipaddress) like this:

server {
    server_name  example.com www.example;
    rewrite ^(.*) http://example.co.uk$1 permanent;
}

Now, I have over 5 or 6 parked domains all pointing to this ipaddress (1 site). So if I have multiple parked domain for the same site, is my only option is to write a really lengthy server_name like this?

server {
    server_name  example.com www.example example.org www.example.org example.net www.example.net examples.com www.examples.com examples.org www.examples.org examples.net www.examples.net;
    rewrite ^(.*) http://example.co.uk$1 permanent;
}

The above doesnt look right to me. But my question is, is this how its done? I mean, if I have many parked domains, I just a add keep adding to my lengthy line in my Nginx config's server block and that should do it with no problem?

Can someone please clarify this for me please...

Neel
  • 1,441
  • 7
  • 21
  • 35

1 Answers1

1

If you make sure that the nginx default server contains your rewrite rule, you don't really need to specify the names at all as the server will react with the default server if an unknown name is requested. You can even define an explicit catch all server like so:

    server {
        listen       80  default_server;
        server_name  _;
        rewrite ^(.*) http://example.co.uk$1 permanent;
    }   

This works because _ is never a valid name.

There are other options, but the best method (IMHO) is top stop "parking" domains. If you don't need them, unregister them.

Sven
  • 98,649
  • 14
  • 180
  • 226
  • Thank you @Sven. But in this method, lets say if a rouge domain points to my ipaddress, wouldnt my server also serve my website for those domains too? Thats why I thought adding individual server names were safer so the default is only used to drop all unrecognized domains. But when having many domains, this method does make sense. Still would like to know the alternative option I got if I want to declare the allowed domain names only. :) – Neel Jan 06 '15 at 22:32
  • Okay, after much consideration, I do feel your suggested solution is the best way to do. Mainly because its a one time config that handles all parked domains pointing to this ip automatically. So thats okay I guess. Unfortunately, I do have to have multiple parked domains mainly due to my site being targeted by squatters who had parked other variations of my domain name (.org, ,net, etc..) which is jeopardizing my site. Thank you Sven for your support. Appreciate that. :) – Neel Jan 07 '15 at 13:12