VisezTrance

  • January 26, 2009 12:14 AM

    Nginx rewrite to a different domain

    By Daniel
    A few days ago I've received an email from someone regarding my earlier post on Nginx subdomain rewrites with some questions on rewriting to a different domain. For example each request on subdomain.domain1.com to be forwarded as a request to subdomain.domain2.com.
    The rewrite module wasn't meant for such requests, just having a string starting with "http://" will trigger a redirection. The problem can be solved however, by proxying the request to the appropriate domain:

    location / {
      if ($host ~* "^(.+)\.domain1\.com$") {
        proxy_pass http://$1.domain2.com;
      }
      proxy_redirect off;
      # Some other code..
    }

    Tags:

    • nginx
  • Monthly Archives

    • October 2013 (2)
    • May 2012 (1)
    • October 2011 (1)
    • September 2011 (2)
    • March 2011 (3)
    • February 2011 (1)
    • January 2011 (1)
    • September 2010 (1)
    • August 2010 (1)
    • June 2010 (1)
    • April 2010 (1)
    • December 2009 (1)
    • October 2009 (1)
    • September 2009 (1)
    • August 2009 (1)
    • July 2009 (2)
    • April 2009 (2)
    • February 2009 (1)
    • January 2009 (2)
    • December 2008 (1)
    • October 2008 (1)
  • Pages

    • About / Contact

2008, © Daniel Mircea