Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

share|improve this question
    
What do you mean by "before the server {} block"? Before nginx has got a request? –  VBart Sep 15 '12 at 15:28
add comment

2 Answers

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/

share|improve this answer
    
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
show 1 more comment
server {
    server_name admin.foobar.website.com;
    location / {
        proxy_pass foobar.othersite.com;
    }
}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.