Virtual host or something else?

Hi,

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….? :P

 <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

I think you are looking something like this:

http://httpd.apache.org/docs/2.2/vhosts/mass.html

http://httpd.apache.org/docs/2.2/mod/mo … alias.html">http://httpd.apache.org/docs/2.2/mod/modvhostalias.html

Hm, maybe, but as far as I've read it still doesn't seem to be how it solves my problem…

Tried with aliases, but that doesn't really work either…

The other "production.mydomain.com" virtual will be ignored because you already have a "production.mydomain.com" virtual host configured. And similar with "staging.mydomain.com".

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.)

yes! that's working correct, but it leaves me with the following issues;

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?

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct