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

Apache Traffic Server

From Wikitech-static
Revision as of 17:36, 22 March 2017 by imported>Ema (→‎Basic configuration)
Jump to navigation Jump to search

Apache Traffic Server is a caching proxy server.

Basic configuration

The basic changes to the default configuration required to get a caching proxy are:

# /etc/trafficserver/remap.config
map http://$origin_server_ip/
reverse_map http://$origin_server_ip/

The following rule can be used as a catchall for mapping any request to a given origin server:

# /etc/trafficserver/remap.config
map / http://deployment-mediawiki05.deployment-prep.eqiad.wmflabs/
# /etc/trafficserver/records.config
CONFIG proxy.config.http.server_ports STRING 3128 3128:ipv6
CONFIG proxy.config.http.cache.required_headers INT 1
CONFIG proxy.config.url_remap.pristine_host_hdr 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.


Show non-default configuration values:

sudo traffic_ctl config diff

Configuration reload:

sudo traffic_ctl config reload

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