Dynamic Subdomain Configuration
Edho Arief
edho at myconan.net
Mon Feb 20 19:39:42 UTC 2012
On Tue, Feb 21, 2012 at 2:28 AM, justin <nginx-forum at nginx.us> wrote:
> Hello,
>
> We provide a subdomain for each user, for example:
>
> paul.ourdomain.com
> jay.ourdomain.com
> bob.ourdomain.com
> xxxxx.ourdomain.com
>
> Currently, I am doing this manually by adding another config in
> /etc/nginx/conf.d for each subdomain. A typical conf looks like:
>
> server {
> listen 80;
>
> server_name paul.ourdomain.com;
>
> root /srv/www/users/paul/wp;
>
> index index.php;
>
> access_log /var/log/nginx/vhosts/paul.access.log;
> error_log /var/log/nginx/vhosts/paul.error.log;
>
> include /etc/nginx/excludes.conf;
> include /etc/nginx/wordpress.conf;
> include /etc/nginx/expires.conf;
> }
>
> Is there I way I can abstract this, and prevent creating a configuration
> for each subdomain? I was reading something about map, but don't fully
> understand it.
>
Probably something like this:
map $host $username {
some.domain.com usera;
another.one.net userb;
}
server {
root /srv/www/users/$username/wp;
access_log /var/log/nginx/vhosts/$username.access.log;
...
}
Or this (without map):
server {
server_name ~^(?<username>.+)\.domain\.com$;
root /srv/www/users/$username/wp;
...
}
--
O< ascii ribbon campaign - stop html mail - www.asciiribbon.org
More information about the nginx
mailing list