Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

share|improve this question
    
How does $username map to $domainname? –  mgorven Aug 12 '12 at 5: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
add comment

1 Answer

up vote 1 down vote accepted

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;
share|improve this answer
add comment

Your Answer

 
discard

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.