You are browsing a read-only backup copy of Wikitech. The live site can be found at

Apache Traffic Server

From Wikitech-static
Revision as of 01:26, 19 January 2017 by imported>Ema
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Apache Traffic Server is a caching proxy server.

Basic configuration

The basic changes required to the default configuration are:

# /etc/trafficserver/remap.config
map http://$origin_server_ip/
reverse_map http://$origin_server_ip/
# /etc/trafficserver/records.config
CONFIG proxy.config.http.server_ports STRING 3128 3128:ipv6
CONFIG proxy.config.http.cache.required_headers INT 1

If proxy.config.http.cache.required is set to 2, which is the default, the origin server is required to set an explicit lifetime, from either Expires or Cache-Control: max-age. By setting required_headers to 1, objects with Last-Modified are considered for caching too. Setting the value to 0 means that no headers are required to make documents cachable.

Lua scripting

ATS plugins can be written in Lua. As an example, this is how to choose an origin server dynamically:

# /etc/trafficserver/remap.config
map http://$origin_server_ip/ @plugin=/usr/lib/trafficserver/modules/ @pparam=/var/tmp/ats-set-backend.lua
reverse_map http://$origin_server_ip/
-- /var/tmp/ats-set-backend.lua
function do_remap()
    url = ts.client_request.get_url()
    if url:match("/api/rest_v1/") then
        return TS_LUA_REMAP_DID_REMAP

External links