Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have around 50 identical domains names with different tld like: domain.net, domain.org, domain.de, domain.biz, domain.ca... now I would like to forward all incoming requests to this domain with and without www on nginx to: http://domain.com how I can do this without need to list every domain?

Something like: forward all request to .domain. or domain.* to: http://domain.com permanent

share|improve this question
add comment

2 Answers

up vote 2 down vote accepted

Use nginx server_name directive with wildcards. Example:

server { 
  server_name domain.com; 

  ... real server ...
}

server { 
  server_name domain.* www.domain.*; 
  rewrite ^ $scheme://domain.com$request_uri? permanent; 
}
share|improve this answer
    
The order doesn't matter for the reason you stated. Wildcard server name entries are only checked if no exact match is found. However, it does matter if no server_name matches, in which case you may want the order reversed, so the redirecting server would still redirect to the desired name. The answer is still a good one, but you should probably remove that comment. –  kolbyjack Jun 9 '11 at 18:34
    
You are absolutely right, I've missed the fact that static names matched before wildcard domains. I've removed this misleading comment. –  AlexD Jun 10 '11 at 3:08
    
works great, thank you. –  Nenad Jun 10 '11 at 11:46
add comment

I never checked using a catch all tld but its worth a try. Don't have access to any nginx install right now, so if you can try the following do let me know too if it worked or not.

server {

            listen   80;
            server_name  domain.* *.domain.*;
            rewrite ^/(.*) http://domain.com/$1 permanent;

}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.