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.

Something like

 server {
   listen 80 default;
   server_name  _ ;
   root /home/drew/sites/$host;
   rewrite ^www(.*) http://$host$1 permanent;
 }
share|improve this question

2 Answers 2

 server {
   listen 80 default;
   server_name the very first;
   rewrite "^www\.(.*)" http://$1 permanent;
 }

Then use respective server declarations with their roots

share|improve this answer
    
What does "server the very first" mean? –  Drew LeSueur Mar 19 '11 at 23:49
    
It is just important taht this server declaration to be the very first for nginx. Maybe even in nginx.conf or make sites-enabled/000-default. No matter what server name you give to it. Put something nonexistent –  Dmytro Leonenko Mar 20 '11 at 1:12
    
If you mark it as default (or default_server in the stable version which you should be using!) then it doesn't matter where in the config it's located. –  Martin Fjordvald Mar 20 '11 at 3:14

I figured out how to mass redirect www sites to non www

 server {
   listen 80 default;
   server_name  _ ;
   if ($host ~ ^(www\.)(?<domain2>.+)$) {
      set $domain2 $2;
      rewrite ^ http://$domain2$request_uri?;
   }
   root /home/drew/sites/$host;
 }
share|improve this answer

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.