Author |
|
rumble
Joined: 22 Aug 2012 Posts: 7 Location: Poland
|
Posted: Wed 22 Aug '12 22:10 Post subject: 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 which contains "projectname"-folder
I have made a file that I enabled with "a2ensite" including the stuff within the code-block.
It is working fine with clientA for "production" and "staging", but of course clientB wont work, since its something like overridden by clientA, right?
Please help me out.
Code: |
<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>
|
|
|
Back to top |
|
James Blond Moderator
Joined: 19 Jan 2006 Posts: 7371 Location: Germany, Next to Hamburg
|
Posted: Fri 24 Aug '12 13:03 Post subject: |
|
|
Why do you have that Aliases inside? |
|
Back to top |
|
rumble
Joined: 22 Aug 2012 Posts: 7 Location: Poland
|
|
Back to top |
|
James Blond Moderator
Joined: 19 Jan 2006 Posts: 7371 Location: Germany, Next to Hamburg
|
Posted: Fri 24 Aug '12 13:14 Post subject: |
|
|
Now I see the mistake. I was bit blind.
The second vhosts override the first vhosts.
you can't have the same server name twice.
correct would be
Code: |
<VirtualHost *:80>
ServerName www.mydomain.com
ServerAlias mydomain.com
DirectoryIndex index.html index.php
DocumentRoot /home/mysite
</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>
<VirtualHost *:80>
ServerName production.mydomain.com
DirectoryIndex index.html index.php
DocumentRoot /home/empty
Alias /clientA/projectA /home/clientA/projectA/production
Alias /clientB/projectA /home/clientB/projectA/production
</VirtualHost>
|
|
|
Back to top |
|
rumble
Joined: 22 Aug 2012 Posts: 7 Location: Poland
|
Posted: Fri 24 Aug '12 13:24 Post subject: |
|
|
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? |
|
Back to top |
|
James Blond Moderator
Joined: 19 Jan 2006 Posts: 7371 Location: Germany, Next to Hamburg
|
|
Back to top |
|
rumble
Joined: 22 Aug 2012 Posts: 7 Location: Poland
|
Posted: Fri 24 Aug '12 15:01 Post subject: |
|
|
will take a look at that then...
but what about my 3)-issue? how can i solve that? |
|
Back to top |
|
James Blond Moderator
Joined: 19 Jan 2006 Posts: 7371 Location: Germany, Next to Hamburg
|
Posted: Sun 26 Aug '12 12:40 Post subject: |
|
|
Use Options -Indexes to prevent that. Or put an empty index.htm into it |
|
Back to top |
|
rumble
Joined: 22 Aug 2012 Posts: 7 Location: Poland
|
Posted: Sun 26 Aug '12 21:58 Post subject: |
|
|
Well, of course thats an option, but it feels like there is a better and more correct way to do it? |
|
Back to top |
|
James Blond Moderator
Joined: 19 Jan 2006 Posts: 7371 Location: Germany, Next to Hamburg
|
Posted: Mon 27 Aug '12 20:40 Post subject: |
|
|
Options -Indexes is the most correct way to disallow Directory Listing. If there is a "most correct" thing. |
|
Back to top |
|
rumble
Joined: 22 Aug 2012 Posts: 7 Location: Poland
|
Posted: Mon 27 Aug '12 20:46 Post subject: |
|
|
yes, I mean, im totally fine doing it for the root-folder. But what I mean is that you don't want a user to be able to figure out the structure when entering staging.mydomain.com/client because they then get a "403/forbidden"-message, instead of a "404-message", you see what I mean? |
|
Back to top |
|
James Blond Moderator
Joined: 19 Jan 2006 Posts: 7371 Location: Germany, Next to Hamburg
|
Posted: Mon 27 Aug '12 20:53 Post subject: |
|
|
Than use more subdomains. Like staging.clientA.mydomain.com and production.clientA.mydomain.com
But with an Alias like Alias /clientA/projectA
entering just /clientA will give a 404 since that path does not exist. |
|
Back to top |
|
rumble
Joined: 22 Aug 2012 Posts: 7 Location: Poland
|
Posted: Wed 29 Aug '12 17:28 Post subject: |
|
|
Hehe, okay. Lets take this from the beginning!
I want to do the following:
For each new project I will create the following within the /home/clients-folder:
clientname-folder and within that a projectname-folder.
When user enters staging.mydomain.com/clientname/projectname, I want to load everything from the clientname/projectname/staging-folder. And if possible I would also like to set so the "DocumentRoot"-folder is now showing /home/clients/clientname/projectname/staging, and also I want error-logs from Apache to be stored in a /home/clients/clientname/projectname/staging/logs-folder.
If the user visits only staging.mydomain.com I would like to either show a 404-message, or a 403-message. Also if the user visits staging.mydomain.com/clientname it should show a 404-message, not a 403-message since then someone can figure out the structure of the folders.
And I know I can setup different virtual hosts for each subdomain, but that will make it look sloppy in my opinion. |
|
Back to top |
|