Rewriting/proxy_pass example

Edho P Arief edhoprima at gmail.com
Wed Dec 9 05:33:48 MSK 2009


On Wed, Dec 9, 2009 at 3:24 AM, Todd Gruben <tgruben at gmail.com> wrote:
> my goal is the following
> i want requests that come in this format...
> http://d1.example.com
> http://d2.example.com
> .
> .
> http://dn.example.com
> to proxy through to my web server as
> http://hardcode.example.com/?site=d1
> http://hardcode.example.com/?site=d2
> .
> .
> http://hardcode.example.com/?site=dn
> I would also like to pass the uri as is and just append the site=d1 to the
> request. for example
> http://d1.example.com/processRequest?arg=1
> to become
> http://hardcode.example.com/processRequest?arg=1&site=d1
>
> Can the proxy_pass/rewrite combination achieve this pattern?
>
> I believe that hardcode.example.com doesn't have to be the same domain as
> the src, its the moving of the subdomain to the argument parameter which i
> desire.
> Thanks
>

server
{
  server_name ~(^d\d)\.example\.com; # server block to use for dN.example.com
  set $name $1; # put the captured dN to $name variable
  rewrite ^ http://hardcode.example.com$uri?$args&site=$name
permanent; # rewrite the url to correct address
}

-- 
O< ascii ribbon campaign - stop html mail - www.asciiribbon.org



More information about the nginx mailing list