0

I know how to set variables and use subroutines with the nginx builtin perl module INSIDE a "server" directive but, what I need to do is to set/rewrite the current domain before.

Let's say, we have a domain like

 admin.foobar.website.com

I want that a request to

 foobar.othersite.com

to point to the first address ( obviously website.com and othersite.com are hosted on the same webserver running nginx :) ).

For reasons I can't explain here, I can not use multiple server_name directive expressions, I have to do this before the server {} block, with perl or anyway possible.

Starfish
  • 2,735
  • 25
  • 28

2 Answers2

0

Please check out the solution that we have developed for this at http://www.logicwreck.com/index.php/2012/09/11/dynamic-vhosts-for-nginx-with-database-storage-of-domain-and-alias-info/

Logic Wreck
  • 1,420
  • 9
  • 8
  • you just dinamically change the root ( and i already can accomplish this ), i need to change the domain itself so that nginx handle this transparently as if admin.foobar.website.com was directly requested. – Simone Margaritelli Sep 14 '12 at 10:54
  • Actually this is being handled easily by this configuration, you will see the domain requested in the browser with the correct root, and if you access an alias of that domain you'll also the the alias name while the document root will be get from the db mapping. – Logic Wreck Sep 14 '12 at 10:57
  • ok but i can't this by setting the root, i need to override the Host http header itself OUTSIDE a server directive ... can't explain why, we have a pretty complicated production environment :) – Simone Margaritelli Sep 14 '12 at 10:58
  • Then this solution might not work for you – Logic Wreck Sep 14 '12 at 11:00
  • unfortunately no, thanks anyway, +1 for the effort :) – Simone Margaritelli Sep 14 '12 at 11:01
  • I think you need to explain this "complicated environment", rather than what you think you need. Two answers here satisfy your stated requirements, but you blew them off without a good explanation of why they fail. –  Sep 15 '12 at 15:46
0
server {
    server_name admin.foobar.website.com;
    location / {
        proxy_pass foobar.othersite.com;
    }
}
VBart
  • 8,309
  • 3
  • 25
  • 26