Solved

Hosting a ton of sites on Linux

Posted on 2006-06-21
11
320 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 250 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 57

Expert Comment

by:giltjr
Comment Utility
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
Comment Utility
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
Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

 

Author Comment

by:MaybeItsJeremy
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
(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
Comment Utility
Thanks, I'm at work now.... So I'll try that when I get home. :)
0
 

Author Comment

by:MaybeItsJeremy
Comment Utility
Thanks to both of you. I have everything working correctly.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

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…
If your site has a few sections that need to be secure when data is transmitted between the server and local computer, such as a /order/ section for ordering or /customer/ which contains customer data, etc it would of course be recommended to secure…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

772 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now