logo
Apache Lounge
Webmasters

 

About Forum Index Downloads Search Register Log in RSS X


Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
Post new topic   Forum Index -> Apache View previous topic :: View next topic
Reply to topic   Topic: Virtual host or something else?
Author
rumble



Joined: 22 Aug 2012
Posts: 7
Location: Poland

PostPosted: Wed 22 Aug '12 22:10    Post subject: Virtual host or something else? Reply with quote

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

PostPosted: Fri 24 Aug '12 13:03    Post subject: Reply with quote

Why do you have that Aliases inside?
Back to top
rumble



Joined: 22 Aug 2012
Posts: 7
Location: Poland

PostPosted: Fri 24 Aug '12 13:07    Post subject: Reply with quote

I thought they would just be affected if the virtual host match?
Im sure this whole config file is setup wrong by me, but any suggestions how I can make the whole thing work with my following structure;
http://staging.mydomain.com/clientA/projectA points to /clientA/projectA/staging, and http://staging.mydomain.com/clientB/projectA points to /clientB/projectA/staging and so on....?
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7371
Location: Germany, Next to Hamburg

PostPosted: Fri 24 Aug '12 13:14    Post subject: Reply with quote

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

PostPosted: Fri 24 Aug '12 13:24    Post subject: Reply with quote

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

PostPosted: Fri 24 Aug '12 14:51    Post subject: Reply with quote

Maybe with AliasMatch
see http://httpd.apache.org/docs/2.2/urlmapping.html#user
Back to top
rumble



Joined: 22 Aug 2012
Posts: 7
Location: Poland

PostPosted: Fri 24 Aug '12 15:01    Post subject: Reply with quote

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

PostPosted: Sun 26 Aug '12 12:40    Post subject: Reply with quote

Use Options -Indexes to prevent that. Or put an empty index.htm into it Wink
Back to top
rumble



Joined: 22 Aug 2012
Posts: 7
Location: Poland

PostPosted: Sun 26 Aug '12 21:58    Post subject: Reply with quote

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

PostPosted: Mon 27 Aug '12 20:40    Post subject: Reply with quote

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

PostPosted: Mon 27 Aug '12 20:46    Post subject: Reply with quote

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

PostPosted: Mon 27 Aug '12 20:53    Post subject: Reply with quote

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

PostPosted: Wed 29 Aug '12 17:28    Post subject: Reply with quote

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


Reply to topic   Topic: Virtual host or something else? View previous topic :: View next topic
Post new topic   Forum Index -> Apache