Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

I want that a request to

to point to the first address ( obviously and 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

Please check out the solution that we have developed for this at

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 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
server {
    location / {
share|improve this answer

Your Answer


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.