nginx重定向www.x.domain.com子域



我想将www.x.domain.com重定向到www.domain.com/.../x。到目前为止,我设法将X.Domain.com重定向到www.domain.com/../x。在我尝试的NGINX配置下方。我在做什么错?

#does not work (www.X.domain.com)                                                                                                                                  
server {                                                                                                                                        
    server_name www.(?<subdomain>).domain.com$;                                                                                           
    location / {                                                                                                                                
        rewrite ^ $scheme://www.domain.com/somedir/$subdomain;                                                                             
   }                                                                                                                                           
}                                                                                                                                               
#works (X.domain.com)                                                                                                                                         
server {                                                                                                                                        
    server_name ~^(?<subdomain>w+).domain.com$;                                                                                           
    location / {                                                                                                                                
        rewrite ^ $scheme://www.domain.com/somedir/$subdomain;                                                                             
   }                                                                                                                                           
}        

您错过了w+~正确零件是

server {                                                                                                                                        
  server_name "~^www.(?<subdomain>w+).domain.com$";                                                                                           
  location / {                                                                                                                                
      rewrite ^ $scheme://www.domain.com/somedir/$subdomain;                                                                             
  }                                                                                                                                           
}         

最新更新