From f2465c369e4fbabd963c44a5c6d33e1c7e1d5f55 Mon Sep 17 00:00:00 2001 From: Rich Bowen Date: Wed, 19 May 2010 00:17:37 +0000 Subject: Better explanation of example for rnd: type RewriteMap git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@945971 13f79535-47bb-0310-9956-ffa450edef68 --- docs/manual/rewrite/rewritemap.html.en | 57 +++++++++++++++++++------------ docs/manual/rewrite/rewritemap.xml | 61 +++++++++++++++++++++------------- 2 files changed, 74 insertions(+), 44 deletions(-) (limited to 'docs') diff --git a/docs/manual/rewrite/rewritemap.html.en b/docs/manual/rewrite/rewritemap.html.en index 1557b3c964..0c85cc4214 100644 --- a/docs/manual/rewrite/rewritemap.html.en +++ b/docs/manual/rewrite/rewritemap.html.en @@ -119,7 +119,7 @@ may be used, and give examples of each.

file.

- # Comment line + # Comment line
MatchingKey SubstValue
MatchingKey SubstValue # comment

@@ -174,20 +174,19 @@ telephone 328

rnd: Randomized Plain Text

-

MapType: rnd, MapSource: Unix filesystem - path to valid regular file

-

This is identical to the Standard Plain Text variant - above but with a special post-processing feature: After - looking up a value it is parsed according to contained - ``|'' characters which have the meaning of - ``or''. In other words they indicate a set of - alternatives from which the actual returned value is - chosen randomly. For example, you might use the following map - file and directives to provide a random load balancing between - several back-end server, via a reverse-proxy. Images are sent - to one of the servers in the 'static' pool, while everything - else is sent to one of the 'dynamic' pool.

-

Example:

+ +

When a MapType of rnd is used, the MapSource is a + filesystem path to a plain-text mapping file, each line of which + contains a key, and one or more values separated by |. + One of these values will be chosen at random if the key is + matched.

+ +

For example, you might use the following map + file and directives to provide a random load balancing between + several back-end server, via a reverse-proxy. Images are sent + to one of the servers in the 'static' pool, while everything + else is sent to one of the 'dynamic' pool.

+

Rewrite map file

 ##
 ##  map.txt -- rewriting map
@@ -196,13 +195,29 @@ telephone  328
 static   www1|www2|www3|www4
 dynamic  www5|www6
 
+

Configuration directives

-RewriteMap servers rnd:/path/to/file/map.txt
-
-RewriteRule ^/(.*\.(png|gif|jpg)) http://${servers:static}/$1 -[NC,P,L]
-RewriteRule ^/(.*) http://${servers:dynamic}/$1 [P,L] -

+ RewriteMap servers rnd:/path/to/file/map.txt
+
+ RewriteRule ^/(.*\.(png|gif|jpg)) http://${servers:static}/$1 [NC,P,L]
+ RewriteRule ^/(.*) http://${servers:dynamic}/$1 [P,L] +

+ +

So, when an image is requested and the first of these rules is + matched, RewriteMap looks up the string + static in the map file, which returns one of the + specified hostnames at random, which is then used in the + RewriteRule target.

+ +

If you wanted to have one of the servers more likely to be chosen + (for example, if one of the server has more memory than the others, + and so can handle more requests) simply list it more times in the + map file.

+ +

+static www1|www1|www2|www3|www4 +

+
top

dbm: DBM Hash File

diff --git a/docs/manual/rewrite/rewritemap.xml b/docs/manual/rewrite/rewritemap.xml index 4173ab7fb5..74f8dc9545 100644 --- a/docs/manual/rewrite/rewritemap.xml +++ b/docs/manual/rewrite/rewritemap.xml @@ -118,7 +118,7 @@ may be used, and give examples of each.

file.

- # Comment line + # Comment line
MatchingKey SubstValue
MatchingKey SubstValue # comment

@@ -174,22 +174,20 @@ telephone 328
rnd: Randomized Plain Text -

MapType: rnd, MapSource: Unix filesystem - path to valid regular file

-

This is identical to the Standard Plain Text variant - above but with a special post-processing feature: After - looking up a value it is parsed according to contained - ``|'' characters which have the meaning of - ``or''. In other words they indicate a set of - alternatives from which the actual returned value is - chosen randomly. For example, you might use the following map - file and directives to provide a random load balancing between - several back-end server, via a reverse-proxy. Images are sent - to one of the servers in the 'static' pool, while everything - else is sent to one of the 'dynamic' pool.

-

Example:

- - Rewrite map file + +

When a MapType of rnd is used, the MapSource is a + filesystem path to a plain-text mapping file, each line of which + contains a key, and one or more values separated by |. + One of these values will be chosen at random if the key is + matched.

+ +

For example, you might use the following map + file and directives to provide a random load balancing between + several back-end server, via a reverse-proxy. Images are sent + to one of the servers in the 'static' pool, while everything + else is sent to one of the 'dynamic' pool.

+ + Rewrite map file
 ##
 ##  map.txt -- rewriting map
@@ -199,14 +197,31 @@ static   www1|www2|www3|www4
 dynamic  www5|www6
 
+ Configuration directives -RewriteMap servers rnd:/path/to/file/map.txt
-
-RewriteRule ^/(.*\.(png|gif|jpg)) http://${servers:static}/$1 -[NC,P,L]
-RewriteRule ^/(.*) http://${servers:dynamic}/$1 [P,L] -
+ RewriteMap servers rnd:/path/to/file/map.txt
+
+ RewriteRule ^/(.*\.(png|gif|jpg)) http://${servers:static}/$1 [NC,P,L]
+ RewriteRule ^/(.*) http://${servers:dynamic}/$1 [P,L] +
+ +

So, when an image is requested and the first of these rules is + matched, RewriteMap looks up the string + static in the map file, which returns one of the + specified hostnames at random, which is then used in the + RewriteRule target.

+ +

If you wanted to have one of the servers more likely to be chosen + (for example, if one of the server has more memory than the others, + and so can handle more requests) simply list it more times in the + map file.

+ + +static www1|www1|www2|www3|www4 + +
+
dbm: DBM Hash File

MapType: -- cgit v1.2.3