From 2ee6350109eba6b8bfe37b40fd1d4eb507b5a247 Mon Sep 17 00:00:00 2001 From: Rich Bowen Date: Fri, 27 Nov 2009 19:09:14 +0000 Subject: [PATCH] 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/rewrite/index.xml.tr | 2 +- docs/manual/rewrite/vhosts.html.en | 125 +++++++++++++++++++++++-- docs/manual/rewrite/vhosts.xml | 119 ++++++++++++++++++++++-- docs/manual/vhosts/mass.html.en | 143 +++-------------------------- docs/manual/vhosts/mass.xml | 137 +++------------------------ docs/manual/vhosts/mass.xml.ko | 2 +- docs/manual/vhosts/mass.xml.tr | 2 +- 7 files changed, 260 insertions(+), 270 deletions(-) diff --git a/docs/manual/rewrite/index.xml.tr b/docs/manual/rewrite/index.xml.tr index 21b891713f..bd3159fa7a 100644 --- a/docs/manual/rewrite/index.xml.tr +++ b/docs/manual/rewrite/index.xml.tr @@ -1,7 +1,7 @@ - + -Using mod_rewrite for virtual hosting - Apache HTTP Server +Dynamic mass virtual hosts with mod_rewrite - Apache HTTP Server @@ -16,7 +16,7 @@
<-
-Apache > HTTP Server > Documentation > Version 2.3 > Rewrite

Using mod_rewrite for virtual hosting

+Apache > HTTP Server > Documentation > Version 2.3 > Rewrite

Dynamic mass virtual hosts with mod_rewrite

Available Languages:  en 

@@ -32,10 +32,14 @@ virtual hosts. You should first consider the alter mod_rewrite.
- +
top
Description:
-

We want to automatically create a virtual host for every user who - has an account on our web server system, without having to create +

We want to automatically create a virtual host for every hostname + which resolves in our domain, without having to create new VirtualHost sections.

In this recipe, we assume that we'll be using the hostname - www.username.example.com for each + www.SITE.example.com for each user, and serve their content out of - /home/username/www.

+ /home/SITE/www.

Solution:
@@ -59,7 +63,10 @@ mod_rewrite.
 RewriteEngine on
-RewriteCond   %{HTTP_HOST}        ^www\.([^.]+)\.example\.com$
+
+RewriteMap    lowercase int:tolower
+
+RewriteCond   %{lowercase:%{HTTP_HOST}}   ^www\.([^.]+)\.example\.com$
 RewriteRule   ^(.*) /home/%1/www$1
 
@@ -72,6 +79,10 @@ RewriteRule ^(.*) /home/%1/www$1 records for each hostname, or a DNS wildcard record. Creating DNS records is beyond the scope of this document. +

The internal tolower RewriteMap directive is used to +ensure that the hostnames being used are all lowercase, so that there is +no ambiguity in the directory structure which must be created.

+

Parentheses used in a RewriteCond are captured into the backreferences %1, %2, etc, while parentheses used in RewriteRule are @@ -88,6 +99,102 @@ dynamic content, and Alias resolution. +

top
+
+

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
+
+

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] +

+

Available Languages:  en 

diff --git a/docs/manual/rewrite/vhosts.xml b/docs/manual/rewrite/vhosts.xml index b7f08140b2..2be57725bc 100644 --- a/docs/manual/rewrite/vhosts.xml +++ b/docs/manual/rewrite/vhosts.xml @@ -23,7 +23,7 @@ Rewrite -Using mod_rewrite for virtual hosting +Dynamic mass virtual hosts with mod_rewrite @@ -47,22 +47,22 @@ mod_rewrite. Advanced techniques and tricks When not to use mod_rewrite -
+
- Virtual Hosts Per User + Virtual Hosts For Artitrary Hostnames
Description:
-

We want to automatically create a virtual host for every user who - has an account on our web server system, without having to create +

We want to automatically create a virtual host for every hostname + which resolves in our domain, without having to create new VirtualHost sections.

In this recipe, we assume that we'll be using the hostname - www.username.example.com for each + www.SITE.example.com for each user, and serve their content out of - /home/username/www.

+ /home/SITE/www.

Solution:
@@ -71,7 +71,10 @@ mod_rewrite.
 RewriteEngine on
-RewriteCond   %{HTTP_HOST}        ^www\.([^.]+)\.example\.com$
+
+RewriteMap    lowercase int:tolower
+
+RewriteCond   %{lowercase:%{HTTP_HOST}}   ^www\.([^.]+)\.example\.com$
 RewriteRule   ^(.*) /home/%1/www$1
 
@@ -84,6 +87,10 @@ RewriteRule ^(.*) /home/%1/www$1 records for each hostname, or a DNS wildcard record. Creating DNS records is beyond the scope of this document. +

The internal tolower RewriteMap directive is used to +ensure that the hostnames being used are all lowercase, so that there is +no ambiguity in the directory structure which must be created.

+

Parentheses used in a RewriteCond are captured into the backreferences %1, %2, etc, while parentheses @@ -103,4 +110,100 @@ dynamic content, and Alias resolution.

+
Dynamic + Virtual Hosts Using <module>mod_rewrite</module> + +

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]
+
+ +
+ +
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] +
+ +
+ 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  | diff --git a/docs/manual/vhosts/mass.xml b/docs/manual/vhosts/mass.xml index 2107056c73..85767f164c 100644 --- a/docs/manual/vhosts/mass.xml +++ b/docs/manual/vhosts/mass.xml @@ -27,7 +27,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.

    @@ -293,127 +295,18 @@ VirtualScriptAliasIP /www/hosts/%0/cgi-bin
    -
    Simple Dynamic - Virtual Hosts Using <module>mod_rewrite</module> - -

    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]
    -
    - +
    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.

    -
    A - Homepages System Using <code>mod_rewrite</code> - -

    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/ -
    - -
    - -
    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] -
    - -
    diff --git a/docs/manual/vhosts/mass.xml.ko b/docs/manual/vhosts/mass.xml.ko index 91b22b9176..72eba329bf 100644 --- a/docs/manual/vhosts/mass.xml.ko +++ b/docs/manual/vhosts/mass.xml.ko @@ -1,7 +1,7 @@ - + +