From 2ee6350109eba6b8bfe37b40fd1d4eb507b5a247 Mon Sep 17 00:00:00 2001 From: Rich Bowen Date: Fri, 27 Nov 2009 19:09:14 +0000 Subject: Moves the rewrite portion of the mass vhosts doc into the rewrite doc tree. We don't actually want to encourage people to use mod_rewrite for this anyways. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@884959 13f79535-47bb-0310-9956-ffa450edef68 --- docs/manual/vhosts/mass.html.en | 143 +++++----------------------------------- 1 file changed, 15 insertions(+), 128 deletions(-) (limited to 'docs/manual/vhosts/mass.html.en') diff --git a/docs/manual/vhosts/mass.html.en b/docs/manual/vhosts/mass.html.en index 445c4e6ab2..0237b33876 100644 --- a/docs/manual/vhosts/mass.html.en +++ b/docs/manual/vhosts/mass.html.en @@ -26,7 +26,9 @@

This document describes how to efficiently serve an - arbitrary number of virtual hosts with the Apache httpd webserver. + arbitrary number of virtual hosts with the Apache httpd webserver. A + separate document discusses using + mod_rewrite to create dynamic mass virtual hosts.

@@ -38,11 +40,8 @@ mod_vhost_alias
  • Using Multiple Virtual Hosting Systems on the Same Server
  • More Efficient IP-Based Virtual Hosting
  • -
  • Simple Dynamic - Virtual Hosts Using mod_rewrite
  • -
  • A - Homepages System Using mod_rewrite
  • -
  • Using a Separate Virtual Host Configuration File
  • +
  • Mass virtual hosts with +mod_rewrite
  • top
    @@ -300,128 +299,16 @@ VirtualScriptAliasIP /www/hosts/%0/cgi-bin
    top
    -

    Simple Dynamic - Virtual Hosts Using mod_rewrite

    - -

    This extract from httpd.conf does the same - thing as the first example. The first - half is very similar to the corresponding part above, except for - some changes, required for backward compatibility and to make the - mod_rewrite part work properly; the second half - configures mod_rewrite to do the actual work.

    - -

    Because mod_rewrite runs before other URI translation - modules (e.g., mod_alias), mod_rewrite must - be told to explicitly ignore any URLs that would have been handled - by those modules. And, because these rules would otherwise bypass - any ScriptAlias directives, we must have - mod_rewrite explicitly enact those mappings.

    - -

    -# 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 /www/hosts>
    - - # ExecCGI is needed here because we can't force
    - # CGI execution in the way that ScriptAlias does
    - Options FollowSymLinks ExecCGI
    -
    -</Directory>
    -
    -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/hosts/${lowercase:%{SERVER_NAME}}/docs/$1
    -
    -## and now deal with CGIs - we have to force a handler
    -RewriteCond %{REQUEST_URI} ^/cgi-bin/
    -RewriteRule ^/(.*)$ /www/hosts/${lowercase:%{SERVER_NAME}}/cgi-bin/$1 [H=cgi-script]
    -

    - -
    top
    -
    -

    A - Homepages System Using mod_rewrite

    - -

    This is similar to the one above, - but also verifies that the hostname falls into a specific subset of - hostnames - in this case, that it looks like - www.SITE.example.com.

    - -

    -RewriteEngine on
    -
    -RewriteMap lowercase int:tolower
    -
    -# allow CGIs to work
    -RewriteCond %{REQUEST_URI} !^/cgi-bin/
    -
    -# Capture the site name in the backreference variable %1
    -RewriteCond ${lowercase:%{SERVER_NAME}} ^www\.([a-z-]+)\.example\.com$
    -
    -# Map the request to the site's document directory
    -RewriteRule ^(.*) /home/%1/$1
    -
    -# define the global CGI directory
    -ScriptAlias /cgi-bin/ /www/std-cgi/ -

    - -
    top
    -
    -

    Using a Separate Virtual Host Configuration File

    - -

    This arrangement uses more advanced mod_rewrite - features to work out the translation from virtual host to document - root, from a separate configuration file. This provides more - flexibility, but requires more complicated configuration.

    - -

    The vhost.map file should look something like - this:

    - -

    -www.customer-1.com /www/customers/1
    -www.customer-2.com /www/customers/2
    -# ...
    -www.customer-N.com /www/customers/N
    -

    - -

    The httpd.conf should contain the following:

    - -

    -RewriteEngine on
    -
    -RewriteMap lowercase int:tolower
    -
    -# define the map file
    -RewriteMap vhost txt:/www/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 [H=cgi-script] -

    - +

    Mass virtual hosts with +mod_rewrite

    + +

    +Mass virtual hosting may also be accomplished using +mod_rewrite, either using simple RewriteRule directives, or using more +complicated techniques such as storing the vhost definitions externally +and accessing them via RewriteMap. These techniques are +discussed in the rewrite +documentation.

    Available Languages:  en  | -- cgit v1.2.3