Virtual host or something else?
I want set up the following structure: staging.mydomain.com/client/projectname production.mydomain.com/client/projectname
For new projects i create the following folders in my /home/-folder:
* "clientname"-folder
* "projectname"-folder
* staging-folder
production-folder</list></list></list>
My apache conf file looks like below right now.
It is working fine with clientA for "production" and "staging", but of course clientB wont work since those vhosts will be ignored.
So, how can I use that so it works with my structure: staging.mydomain.com/clientA/projectA points to /clientA/projectA/staging, and staging.mydomain.com/clientB/projectA points to /clientB/projectA/staging and so on….?
<virtualhost *:80="">ServerName www.mydomain.com
ServerAlias mydomain.com
DirectoryIndex index.html index.php
DocumentRoot /home/mysite</virtualhost>
<virtualhost *:80="">ServerName production.mydomain.com
ServerAlias production.mydomain.com
DirectoryIndex index.html index.php
DocumentRoot /home/clientA/projectA/production
Alias /clientA/projectA /home/clientA/projectA/production</virtualhost>
<virtualhost *:80="">ServerName staging.mydomain.com
ServerAlias staging.mydomain.com
DirectoryIndex index.html index.php
DocumentRoot /home/clientA/projectA/staging
Alias /clientA/projectA /home/clientA/projectA/staging</virtualhost>
<virtualhost *:80="">ServerName production.mydomain.com
ServerAlias production.mydomain.com
DirectoryIndex index.html index.php
DocumentRoot /home/clientB/projectA/production
Alias /clientB/projectA /home/clientB/projectA/production</virtualhost>
<virtualhost *:80="">ServerName staging.mydomain.com
ServerAlias staging.mydomain.com
DirectoryIndex index.html index.php
DocumentRoot /home/clientB/projectA/staging
Alias /clientB/projectA /home/clientB/projectA/staging</virtualhost>
4 Replies
Tried with aliases, but that doesn't really work either…
You will need to consolidate all the Alias statements into each of the virtual hosts, like this (based on the example you posted originally):
<virtualhost *:80="">ServerName www.mydomain.com
ServerAlias mydomain.com
DirectoryIndex index.html index.php
DocumentRoot /home/mysite</virtualhost>
<virtualhost *:80="">ServerName production.mydomain.com
DirectoryIndex index.html index.php
DocumentRoot /home/mysite
Alias /clientA/projectA /home/clientA/projectA/production
Alias /clientB/projectA /home/clientB/projectA/production</virtualhost>
<virtualhost *:80="">ServerName staging.mydomain.com
DirectoryIndex index.html index.php
DocumentRoot /home/mysite
Alias /clientA/projectA /home/clientA/projectA/staging
Alias /clientB/projectA /home/clientB/projectA/staging</virtualhost>
(I've set the DocumentRoot in each of the additional sites to point to the same as your main site - usually, you don't want clientB to see the work you've done for clientA as the default website view, since this might distract your client's attention away from the project you're working on.)
1. i have to manually insert a new alias for each client. Is it possible to do something like a AliasMatch with regexp or something?
2. the document root will be /home/mysite no matter what the matching url is, not a big issue, but is there a way to control so the document root will be /home/clientA/projectA/staging for example?
3. if the user visits staging.mydomain.com the will be able to list the directories, guess you can deny directory listing for that folder, but what about next level? If the user enter staging.mydomain.com/clientA, then I don't want it to be a valid route, more like a "File Not found" or something like that?