Mapping sites to other sites without using FastCGI/DB

Brian Kirkbride brian.kirkbride at deeperbydesign.com
Wed Feb 27 23:30:24 MSK 2008


Igor Sysoev wrote:
> On Wed, Feb 27, 2008 at 01:18:24PM -0600, Brian Kirkbride wrote:
> 
>> I'm new to Nginx but have been very impressed with it -- thanks for 
>> contributing this great software.
>>
>> I have a mass virtual hosting setup, all sites have the same config 
>> and will be served with server_name * (wildcard).  The config is very 
>> simple, just serving some static files.  I want to keep the Nginx 
>> boxes as simple and light as possible -- no FastCGI, no database.
>>
>> Some domains will simply be an alias to another domain.  I know that 
>> for one or two domains, you could simply do a rewrite from 
>> ALIASDOMAIN.com/(.*) to REALDOMAIN/$1, but our situation is more 
>> dynamic and we can't update the config file all the time.
>>
>> Is there as way to have:
>>
>> docroot/
>>   realdomain.com/
>>     [content]
>>   aliasdomain.com/
>>     aliased_to
>>
>> where aliased_to is a text file containing the real domain?
>>
>> Or what about:
>>
>> docroot/
>>   realdomain.com/
>>     [content]
>>   aliasdomain.com/
>>     aliasto_realdomain.com
>>
>> Something like that?
>>
>> In apache mod_rewrite I would do this using maps, but my Nginx skills 
>> are weak!
> 
> Use map, http://wiki.codemongers.com/NginxHttpMapModule
> 
> http {
>      map  $http_host   $root {
>         realdomain.com        realdomain.com;
>         aliasdomain.com       realdomain.com;
>         ...
>      }
> 
>      server {
>           locaiton / {
>               root    /docroot/$root;
>               ...
>           }
>      }
> }
> 

Thanks Igor!

I can't believe I missed the map module while Googling.  That should 
work great for our problem.  We will just regenerate a mapfile to be 
included in the config and then kill -HUP nginx on changes.

Our host map be very large, possibly several thousand entries?  Will 
this slow things down very much?

Best,
Brian





More information about the nginx mailing list