Vhost support

Mark Constable markc at renta.net
Sat Jan 29 15:37:02 MSK 2011

On 29/01/11, António P. P. Almeida wrote:
> Make it:
> server_name ~^(?<p1>[^\.]*)[\.]*(?<p2>[^\.]*)[\.]*(?<p3>[^\.]*)[\.]*(?<p4>[^\.]+)\.(?<p5>[^\.]+)$;
> Forgot to escape the "." in the named capturing groups.

Thanks Antonio, this does indeed work. The only downside I can see is
that the system file path is something like /var/www////com/domain/,
when there are less than 5 parts, but it still seems to work okay.

server {
  listen 80;
  server_name ~^(?<p1>[^\.]*)[\.]*(?<p2>[^\.]*)[\.]*(?<p3>[^\.]*)[\.]*(?<p4>[^\.]*)[\.]*(?<p5>[^\.]*)$;

  location / {
    root /var/www/$p5/$p4/$p3/$p2/$p1;
    index  index.html index.htm index.jsx index.php;

I'd still be interested to do this without requiring a regex as all
it would take is something like this small amount of code in a module,
or as a patch to core...

char *add_path_element(char *dest, char *element)
    *dest++ = '/';
    return dest + strlen(element);

    server_name = ap_get_server_name(r);
    buf = apr_pstrdup(r->pool, server_name);
    rvp = apr_palloc(r->pool, strlen(buf)+1);

    r->canonical_filename = "";

   /* Work out the reverse path */
    for (p = rvp, q = buf+strlen(buf); q >= buf; q--) {
        if (*q == '.') {
            *q = '\0';
            p = add_path_element(p, q+1);
    p = add_path_element(p,buf);

Anyone care to suggest where is the best place to start to look for
a module or patch to add something like the above?


More information about the nginx mailing list