Link to home
Start Free TrialLog in
Avatar of MaybeItsJeremy
MaybeItsJeremy

asked on

Hosting a ton of sites on Linux

I'm in the deployement stage of launching a hosted content management solution, most of the customers will be hosting their site with us to make things easier on them, I've never done large scale hosting outside of IIS on Win 2003. For this project, I'm actually using Linux: Red Hat Fedora Core 4 with Apache 2.

Each account will get 500MB - 1000MB of space, most will be using only 500MB, so to play it safe, we're going to limit the number of hosting clients to 400 per server (2x 200 gig drives each).

Are 400 virtual hosts in the Apache config file the way to go, even with 400 entires? Is there an alternative?


Also, the format I've been using for virtual hosts is as follows:

<VirtualHost site.com:80>
    DocumentRoot PATH_TO_DOCS
    ServerName site.com
</VirtualHost>


But how do I get it to work with WWW as well, do I have to add the domain twice?


<VirtualHost www.site.com:80>
    DocumentRoot PATH_TO_DOCS
    ServerName www.site.com
</VirtualHost>


If there is an alternative to this, I'll glady pay for it if I have to. If there are no alternative, would 400 domains in the virtual host config be any sort of memory hog? The sites themself are pure HTML files after they are saved from the CMS, so processing them isn't much of an issue.

Thanks!
ASKER CERTIFIED SOLUTION
Avatar of giltjr
giltjr
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Just to add to the excellent adevise above, there are a few solutions for working with both www.domain.com and domain.com.

Traditionally, you would use the built in function in Apache for a ServerAlias:

<VirtualHost site.com:80>
    DocumentRoot PATH_TO_DOCS
    ServerName site.com
    ServerAlias www.site.com
</VirtualHost>

Unfortunately, this lead to great abuse of the search engines, as some people would register 100's of domains, and point them all to the same site.

Therefore, for search engine optimization purposes, it makes more sense to set up a second entry, and do a permanent redirect like this:

<VirtualHost site.com:80>
    DocumentRoot PATH_TO_DOCS
    ServerName www.site.com
</VirtualHost>

<VirtualHost site.com:80>
    DocumentRoot PATH_TO_DOCS
    ServerName site.com
    Redirect Permanent / http://www.site.com
</VirtualHost>
One correction to the above -

<VirtualHost site.com:80>
    DocumentRoot PATH_TO_DOCS
    ServerName site.com
    Redirect Permanent / http://www.site.com/
</VirtualHost>

(I forgot the trailing slash on the redirect.)
periwinkle, I must have had way too much to drink last night, or not enough.  I completely forgot about ServerAlias, but never knew about Redirect Permanent.
Avatar of MaybeItsJeremy
MaybeItsJeremy

ASKER

Ok, I really like the rewrite method as it will make individual updates much faster... What can I do to dynamically have it work work with www as well? This is what I am using now:






# get the server name from the Host: header
UseCanonicalName Off

# splittable logs
LogFormat "%{Host}i %h %l %u %t \"%r\" %s %b" vcommon
CustomLog logs/access_log vcommon

<Directory C:/AppServ/www/>
# ExecCGI is needed here because we can't force
# CGI execution in the way that ScriptAlias does
Options FollowSymLinks ExecCGI
</Directory>

# now for the hard bit

RewriteEngine On

# a ServerName derived from a Host: header may be any case at all
RewriteMap lowercase int:tolower

## deal with normal documents first:
# allow Alias /icons/ to work - repeat for other aliases
RewriteCond %{REQUEST_URI} !^/icons/
# allow CGIs to work
RewriteCond %{REQUEST_URI} !^/cgi-bin/
# do the magic

RewriteRule ^/(.*)$ www/${lowercase:%{SERVER_NAME}}/$1

## and now deal with CGIs - we have to force a MIME type
RewriteCond %{REQUEST_URI} ^/cgi-bin/
RewriteRule ^/(.*)$ www/${lowercase:%{SERVER_NAME}}/cgi-bin/$1 [T=application/x-httpd-cgi]

# that's it!
Ok, got it working with and without www. (if this can be improved in any way, let me know:


RewriteEngine On
RewriteMap lowercase int:tolower

RewriteCond   %{SERVER_NAME}                 ^www\.(.*)$
RewriteRule   ^(.+)                        %{SERVER_NAME}$1          [C]
RewriteRule   ^www\.(.*) www/$1


RewriteCond   %{SERVER_NAME}                 !^www\.(.*)$
RewriteRule   ^(.+)                        %{SERVER_NAME}$1          [C]
RewriteRule   ^(.*) www/$1
I believe you can issue the 301 status, too with mod_rewrite - that's the way that the search engines prefer.
How would I go about doing that? Can it be placed into the code I submitted earlier?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks, I'm at work now.... So I'll try that when I get home. :)
Thanks to both of you. I have everything working correctly.