[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

Hosting a ton of sites on Linux

Posted on 2006-06-21
11
Medium Priority
?
363 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
  • 5
  • 4
  • 2
11 Comments
 
LVL 57

Accepted Solution

by:
giltjr earned 1000 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
Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

 
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 1000 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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying 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

As Wikipedia explains 'robots.txt' as -- the robot exclusion standard, also known as the Robots Exclusion Protocol or robots.txt protocol, is a convention to prevent cooperating web spiders and other web robots from accessing all or part of a websit…
The title says it all. Writing any type of PHP Application or API code that provides high throughput, while under a heavy load, seems to be an arcane art form (Black Magic). This article aims to provide some general guidelines for producing this typ…
SQL Database Recovery Software repairs the MDF & NDF Files, corrupted due to hardware related issues or software related errors. Provides preview of recovered database objects and allows saving in either MSSQL, CSV, HTML or XLS format. Ensures recov…
The video will let you know the exact process to import OST/PST files to the cloud based Office 365 mailboxes. Using Kernel Import PST to Office 365 tool, one can quickly import numerous OST/PST files to Office 365. Besides this, the tool also comes…
Suggested Courses
Course of the Month10 days, 20 hours left to enroll

612 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