2

My setup is:

  • Nginx(80) as a transparent proxy
  • Apache(81) as back-end web server

The paths to each domain on the server are like this:

/var/www/$username/data/www/$domainname

Of course to access the files you need to use the domain name of each website. But I want a way to access all the domains using an URL like this:

http://dm.some.com/clientdomain.com 

How can I do this? This URL will be used to access ONLY static files, so I think it will be best to use Nginx for this.

Jim
  • 410
  • 4
  • 14
  • How does $username map to $domainname? – mgorven Aug 12 '12 at 05:46
  • $username is just the username of the user and it can be anything. A user can have many domains and $domainname is a folder named clientdomain.com – Jim Aug 12 '12 at 11:20

1 Answers1

1

The problem is determining the username for a specific domain. Actually getting nginx to search through all the usernames to find this is tricky and not optimal. There are two approaches I can think of.

Symlink all domains into one directory

Create a directory with symlinks to every domain, for example:

/srv/www/all/example.com -> /srv/www/alice/data/www/example.com
/srv/www/all/example.org -> /srv/www/alice/data/www/example.org
/srv/www/all/example.net -> /srv/www/bob/data/www/example.net

And then just setup a virtual host in nginx with /srv/www/all as the root.

Manually configure the mapping in nginx

The map module is probably the simplest to maintain.

map $uri $username {
    /example.com    alice;
    /example.org    alice;
    /example.net    bob;
}

root /srv/www;
rewrite ^/([^/]+)/(.*)$ /$username/data/www/$1/$2 last;
mgorven
  • 30,615
  • 7
  • 79
  • 122