redirect subdomain to internal location

António P. P. Almeida appa at perusio.net
Wed May 25 15:57:54 MSD 2011


On 25 Mai 2011 12h43 WEST, nginx-forum at nginx.us wrote:

> How would I test for the following subdomains?
>
> www
> www4
> any other subdomain 
>
> Then redirect each to a corresponding internal location?
>
> I am using the following code to get the 'any other subdomain' but
> can't get the redirect to a location such as @any_subd working?
>
> if ($host ~* "(.*)\.tm2app\.com") {
> set $subd $1;
> }

Do you mean that *all* subdomains should use the same location?

If so use a wildcard in the server_name directive:

server {
  server_name *.tmp2app.com;

  (...)
}

If the subdomains always start by www and they're to be handled
differently than other do this for www1, www2...www99

server {
  server_name "~^www\d{1,2}\.tmp2app\.com$";
  (...)
}

--- appa



> Thanks for your help.
>
> Chris
>
> Posted at Nginx Forum:
> http://forum.nginx.org/read.php?2,200694,200694#msg-200694
>
>
> _______________________________________________
> nginx mailing list
> nginx at nginx.org
> http://nginx.org/mailman/listinfo/nginx



More information about the nginx mailing list