Forum Moderators: phranque

Message Too Old, No Replies

Multiple Vhosts configuration

         

filekilla

11:24 pm on Mar 25, 2005 (gmt 0)

10+ Year Member



I have numerous namebased vhosts on apache 2.0 server for windows. I have been adding accounts maually into the httpd.conf which has become quite a pain recently as the numbers of vhosts inserted has increased considerably. This led me to find other ways of handling vhost. What I think would be best solution is to somehow apache read directories and convert them to name based vhost automatically for example

Directory: c:\vhosts\user1
Directory" c:\vhosts\user2

so when users type user1.example.com or example.com/user1 , Apache reads the content of user1 and if someone types user2.example.com or example.com/user2, Apache reads the user2 directory.

sitz

4:26 am on Mar 26, 2005 (gmt 0)

10+ Year Member



Home-grown solutions aside (and I've seen some creative ones), your two easiest options are:

1) [httpd.apache.org ]

2) Listed at [httpd.apache.org ], under 'Mass Virtual Hosting'.

The catch to these solutions is that you become somewhat limited in the number of per-site customizations you can do. Of course, in large-scale environments, this problem is generally self-correcting; solutions are found that don't require customizations, or the system has a habit of collapsing under its own weight. At a former job, I ran server that hosted ~9000 domains or so, using a variation on method #2 above.

As a final note, when the number of VirtualHosts gets REALLY large, you run into a technical issue (rather than simple administrative ones. For some value of 'simple' =) ); Apache allocates a block of memory for each <VirtualHost> container. When you start getting thousands of these, Apache's memory footprint grows significantly, which can be an issue *especially* when using Apache in pre-fork mode (I believe the win32 version of Apache uses a threaded model, yes? In which case, you may be less affected by this, as would users of Apache 2 in threaded mode).

filekilla

7:17 pm on Mar 26, 2005 (gmt 0)

10+ Year Member



I am trying to do the mass virtual hosting but it keeps on giving me my server index page when trying to access a vhost sub-domain and a 404 when trying to access a vhost domain.

my directory structure is this:
c:\apache\htdocs <----- server root
c:\apache\htdocs\members\user1 <---- user1 root
c:\apache\htdocs\members\sub1 <---- subdomain root

I am testing it on a Fresh install of apache 2.05. Server port is set to 8080 and Listen port is 8080 as well.

my vhost.map
www.example.com:8080 c:/apache/htdocs/members/user1
sub.mydomain.com:8080 c:/apache/htdocs/subdomains/sub1

new content added to htdocs:
RewriteEngine on

RewriteMap lowercase int:tolower

# define the map file
RewriteMap vhost txt:c:/apache/conf/vhost.map

# deal with aliases as above
RewriteCond %{REQUEST_URI} !^/icons/
RewriteCond %{REQUEST_URI} !^/cgi-bin/
RewriteCond ${lowercase:%{SERVER_NAME}} ^(.+)$
# this does the file-based remap
RewriteCond ${vhost:%1} ^(/.*)$
RewriteRule ^/(.*)$ %1/docs/$1

RewriteCond %{REQUEST_URI} ^/cgi-bin/
RewriteCond ${lowercase:%{SERVER_NAME}} ^(.+)$
RewriteCond ${vhost:%1} ^(/.*)$
RewriteRule ^/(.*)$ %1/cgi-bin/$1

sitz

10:21 pm on Mar 26, 2005 (gmt 0)

10+ Year Member



I appear to be not on the mightiest of rolls today with regards to fully comprehending issues; are all the virtualhosts you're using in the form of:

username.domain.com

?

If so, you could do something like this:


RewriteEngine on
#
# place the "username" portion of
# "username.domain.com" into %1
RewriteCond %{HTTP_HOST} ^([^\.]+)\.
#
# place the requested path into $1 and Rewrite
RewriteRule ^/(.*) c:\vhosts\%1\$1 [L]

If you're hosting several hundred domains in the form of 'www.domain.com', 'www.anotherdomain.com', etc, then the RewriteMap (or mod_vhost_alias) is the way to go.