
36
Chapter 5
Reverse Proxy and HTTP Redirects
Using mapping rules
Traffic Server uses two types of mapping rules for HTTP reverse proxy:
•
A map rule translates the URL in client requests into the URL where the content is located (refer to “Map
rules,” below)
•
A reverse-map rule translates the URL in origin server redirect responses to point to the Traffic Server so
that clients are redirected to Traffic Server instead of accessing an origin server directly (refer to “Reverse-
map rules,” below)
Both map and reverse-map rules consist of a target (origin) URL and a replacement (destination) URL. In a
map rule, the target URL points to Traffic Server and the replacement URL specifies where the original
content is located. In a reverse-map rule, the target URL specifies where the original content is located and the
replacement URL points to Traffic Server. Traffic Server stores mapping rules in the
remap.config
file
located in Traffic Server’s
config
directory.
Map rules
When a Traffic Server in reverse proxy mode receives an HTTP client request, it first constructs a complete
request URL from the relative URL and its headers. Traffic Server then compares the complete request URL
with its list of target URLs in the
remap.config
file, looking for a match. For the request URL to match a
target URL, the following conditions must be true:
•
The scheme of both URLs must be the same
•
The host in both URLs must be the same (if the request URL contains an unqualified hostname, it will
never match a target URL with a fully qualified hostname)
•
The ports in both URLs must be the same (if no port is specified in a URL, the default port for the scheme
of the URL is used)
•
The path portion of the target URL must match a prefix of the request URL
If Traffic Server finds a match, it translates the request URL into the replacement URL listed in the map rule.
It sets the host and path of the request URL to match the replacement URL. If the URL contains path prefixes,
Traffic Server removes the prefix of the path that matches the target URL and substitutes it with the path from
the replacement URL.
If two mappings match a request URL, Traffic Server applies the first mapping listed in the
remap.config
file.
Reverse-map rules
Reverse-map rules rewrite location headers in origin server responses, instead of client requests. Origin servers
use location headers to redirect clients to another location.
For example if there is a directory
/pub
on an origin server at
www.molasses.com
, and a client sends a
request to that origin server for
/pub
, the origin server will probably reply with a redirect to
http://
www.test.com/pub/
to let the client know that it was a directory it had requested, instead of a document.
(A common use of redirects is to normalize URLs so that clients can bookmark documents properly.)
Traffic Server uses reverse-map rules to prevent redirects from origin servers from causing clients to bypass
the Traffic Server in favor of direct access to the origin servers.
Setting map and reverse-map rules
You can set mapping rules by using Traffic Manager or by editing a configuration file manually. Both
procedures are described below.
To create a mapping rule from Traffic Manager:
1. Access Traffic Manager from your browser (refer to
Accessing Traffic Manager‚ on page 8
).
2. On the Configure tab, click the Routing button.