Solved

Hosting a ton of sites on Linux

Posted on 2006-06-21
11
347 Views
Last Modified: 2010-05-18
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!
0
Comment
Question by:MaybeItsJeremy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 2
11 Comments
 
LVL 57

Accepted Solution

by:
giltjr earned 250 total points
ID: 16956884
Try looking at http://httpd.apache.org/docs/2.0/vhosts/mass.html  which talks about how to do mass dynamic virtual hosting.

If mass dynamic virtual hosting does not meet your requirments then you would need to code something like:

NameVirtualHost *:80

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

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


You could put the host name on the <VirtualHost xxx:80> statement, but *:80 also works.  You would have to add in pairs.  I have never worked with rewirtes (mod-rewrite), but you may be able to do something where if somebody enters site.com, it is changed to www.site.com.

You could configure the defualt virtual host site to a single page with a javascript that if a host name is entered that does not exist.
0
 
LVL 15

Expert Comment

by:periwinkle
ID: 16959000
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>
0
 
LVL 15

Expert Comment

by:periwinkle
ID: 16959149
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.)
0
Don't Miss ATEN at InfoComm 2017!

Visit booth #2167 to see the  new ATEN VM3200 32 x 32 Modular Matrix Switch. Other highlights include the VE8950 4K HDMI Over IP Extender, VS1912 12-Port DP Video Wall Media Player  and VK2100 ATEN Control System. Register now with Free Pass Code ATEN288!

 
LVL 57

Expert Comment

by:giltjr
ID: 16959178
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.
0
 

Author Comment

by:MaybeItsJeremy
ID: 16965225
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!
0
 

Author Comment

by:MaybeItsJeremy
ID: 16965730
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
0
 
LVL 15

Expert Comment

by:periwinkle
ID: 16968367
I believe you can issue the 301 status, too with mod_rewrite - that's the way that the search engines prefer.
0
 

Author Comment

by:MaybeItsJeremy
ID: 16968709
How would I go about doing that? Can it be placed into the code I submitted earlier?
0
 
LVL 15

Assisted Solution

by:periwinkle
periwinkle earned 250 total points
ID: 16968805
(let me preface this by saying I'm not a mod_rewrite guru - and I haven't tried this ;) )

Yes, I believe so - it's a flag, from what I gather from the docs:

redirect|R  [=code]' (force redirect)

Prefix Substitution with http://thishost[:thisport]/ (which makes the new URL a URI) to force a external redirection. If no code is given, a HTTP response of 302 (MOVED TEMPORARILY) will be returned. If you want to use other response codes in the range 300-400, simply specify the appropriate number or use one of the following symbolic names: temp (default), permanent, seeother. Use this for rules to canonicalize the URL and return it to the client - to translate ``/~'' into ``/u/'', or to always append a slash to /u/user, etc.

Note: When you use this flag, make sure that the substitution field is a valid URL! Otherwise, you will be redirecting to an invalid location. Remember that this flag on its own will only prepend http://thishost[:thisport]/ to the URL, and rewriting will continue. Usually, you will want to stop rewriting at this point, and redirect immediately. To stop rewriting, you should add the 'L' flag.

... so it seems like you'd use [R=301] on the RewriteRule   ^(.*) www/$1 statement like:

RewriteRule   ^(.*) www/$1       [R=301]
0
 

Author Comment

by:MaybeItsJeremy
ID: 16968935
Thanks, I'm at work now.... So I'll try that when I get home. :)
0
 

Author Comment

by:MaybeItsJeremy
ID: 16979482
Thanks to both of you. I have everything working correctly.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

If you are running a LAMP infrastructure, this little code snippet is very helpful if you are serving lots of HTML, JavaScript and CSS-related information. The mod_deflate module, which is part of the Apache 2.2 application, provides the DEFLATE…
Hi, in this article I'm going to teach you how to run your own site, and how to let people in (without IP). I'll talk about and explain each step... :) By the way, everything in this Tutorial is completely free and legal. This article is for …
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question