Forum Moderators: phranque

Message Too Old, No Replies

1 Virtual Host, Multiple Domains

         

dunnma

9:54 pm on Aug 23, 2009 (gmt 0)

10+ Year Member



I have a server running Apache 2.2.8 that already has a dozen or so various Virtual hosts.

One of my "products" runs off of subdomains. So company.domain.com. Everything works great for it using The RewriteMap system.

Now the "problem". Some clients want to be able to use their own domain. They can enter "multiple" domains via their settings form. Currently I have to manually add their domain to the ServerAlias line (and I also don't think it would be right to duplicate the VirtualHost and create a new one).

So it might look like:

ServerName www.mydomain.com
ServerAlias mydomain.com *.mydomain.com theirdomain.com www.theirdomain.com *.theirdomain.com theirdomain2.com www.theirdomain2.com *.theirdomain2.com

Is there anyway to automate this? I.e. can I just have PHP modify a txt file (just like I do for the RewriteMap stuff), and then include it?

Since I can have hundreds/thousands (boy would that be nice) of external domains. Most accounts might have at most 1. Some might have multiple which I would have to user Mod Rewrite to "combine".

Any help would be greatly appreciated. Below is the current VirtualHost configuration.

Thanks!

<VirtualHost *:80>
ServerName www.mydomain.com
ServerAlias mydomain.com *.mydomain.com
ServerAdmin root@mydomain.com
DocumentRoot /var/www/html/mydomain.com/html
ErrorLog logs/mydomain.com/error
CustomLog logs/mydomain.com/access common
DirectoryIndex index.html index.htm index.shtml index.shtm index.php
RewriteMap site_ids txt:/var/www/html/mydomain.com/includes/site_ids.txt
RewriteMap lowercase int:tolower
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.+) [NC]
RewriteRule ^(.*)$ [%1$1...] [R,L]
<Directory /var/www/html/mydomain.com/html>
Options All
AllowOverride All
<IfModule mod_expires.c>
ExpiresActive on
ExpiresDefault "access plus 10 years"
ExpiresByType text/html "now"
ExpiresByType text/xml "now"
ExpiresByType text/css "access plus 8 hours"
ExpiresByType text/plain "access plus 8 hours"
ExpiresByType application/x-javascript "access plus 8 hours"
ExpiresByType application/x-shockwave-flash "access plus 8 hours"
ExpiresByType application/pdf "access plus 8 hours"
ExpiresByType image/gif "access plus 8 hours"
ExpiresByType image/png "access plus 8 hours"
ExpiresByType image/jpeg "access plus 8 hours"
ExpiresByType image/x-icon "access plus 8 hours"
ExpiresByType video/x-flv "access plus 8 hours"
ExpiresByType video/quicktime "access plus 8 hours"
</IfModule>
Include conf/mydomain_rewrites.conf
</Directory>
Include conf/mod_deflate.conf
</VirtualHost>

dunnma

10:13 pm on Aug 23, 2009 (gmt 0)

10+ Year Member



I found a post from 2005 that said to put this virtual host first in the list, and then anything that is not matched will automatically go into it.

Would this be a "cheap" way to solve it? Obviously if I have another "product" that worked the same way I could not handle it this way on the server.

Thanks!

jdMorgan

10:28 pm on Aug 23, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you add another "product," see the "Mass Virtual Hosting" example in the Apache URL Rewriting Guide for another way to do this.

Jim

dunnma

10:46 pm on Aug 23, 2009 (gmt 0)

10+ Year Member



Yeah...I found that too...but if I am reading that correctly then I need to have a "folder" for each domain?

Apache's documentation (at least from my perspective) is not very "human" understandable. The first place I come to (after doing a Google search first) is here and to see "you" as you are "Mr. Apache".

I will do what I can to prevent having a similar situation to this.

Thanks!

jdMorgan

11:02 pm on Aug 23, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Create the folder as part of your clients' "registration" perhaps.

This folder is simply the root of the space where their files are stored. If all of their requests go to a script instead of resolving to a physical filespace, then that "folder" need not exist -- Just point them all to the same vHost and the same script, and generate whatever content is needed using your script(s).

The Apache docs are good when you've got the basics and need the details fast. They are not beginner-level, though, and were never meant to be, because most of them were written back when only 'formally-trained' Webmasters could host sites on the Web, and the newer versions (e.g. Apache 2.x) simply followed the earlier examples.

However, when you're in a hurry to find one particular detail, you'll appreciate that the documentation is short, sweet, and to the point -- You don't have to wade through chapter after chapter of irrelevant tutorial material to find what you need...

Jim

dunnma

12:50 am on Aug 24, 2009 (gmt 0)

10+ Year Member



Very true about the documentation.

As far as my setup goes, I have my 1 product folder that contains all of the html/php files. Basically I only want one folder to maintain and would rather not have 200 folders with the same content in it (i.e. make a change to one file, have to do it in numerous locations) - plus it is a waste of server space.

Unless of course I am misunderstanding (which is very likely).

jdMorgan

12:58 am on Aug 24, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Basically, I was saying is that by modifying the example given in the cited app note, you can do it any way you like.

Jim