Tutorial

How to Set Up Apache Traffic Server as a Reverse-Proxy on Ubuntu 14.04

Published on October 3, 2015
How to Set Up Apache Traffic Server as a Reverse-Proxy on Ubuntu 14.04

Introduction

Apache Traffic Server is a highly scalable caching proxy server capable of handling large volumes of concurrent requests while maintaining a very low latency. Compared to other popular proxy servers, such as Varnish or Squid, it usually consumes less memory and responds faster. It is also designed to make the most of modern multi-core processors. Depending on your requirements, you can use it as a reverse proxy or as a forward proxy.

This tutorial will cover how to install Apache Traffic Server on Ubuntu 14.04 and configure it to behave as a caching reverse proxy.

Prerequisites

To follow this tutorial, you will need:

Step 1 — Installing Traffic Server

Because Traffic Server is available on Ubuntu 14.04’s default repositories, you can install it using apt-get. Make sure you update your package index files before you do so.

  1. sudo apt-get update && sudo apt-get install trafficserver

Traffic Server listens on port 8080 by default. You can use a browser to visit http://your_server_ip:8080/ now. However, you will see an error because you haven’t configured it yet.

Step 2 — Installing a Web Server

By definition, a proxy server acts as an intermediary between external users and a web server. Therefore, before you begin configuring Traffic Server, you should install a web server such as Apache HTTP Server on your machine.

Install and start Apache using apt-get.

  1. sudo apt-get install apache2

You can now use a browser and visit http://your_server_ip/ to see Apache’s welcome page.

Step 3 — Disabling Remote Access to the Web Server

Apache accepts connections on all network interfaces by default. By configuring it to accept connections only on the loopback interface, you can make sure that it is inaccessible to remote users.

Open ports.conf using nano or your favorite text editor.

  1. sudo nano /etc/apache2/ports.conf

Search for the line containing the Listen 80 directive and change it to:

ports.conf
Listen	127.0.0.1:80

Save and exit the file.

Next, open apache2.conf.

  1. sudo nano /etc/apache2/apache2.conf

Add the following line at the end of the file:

apache2.conf
ServerName localhost

Save and close the file.

To apply the configuration changes, restart Apache using the following command:

  1. sudo service apache2 restart

Try using a browser to visit http://your_server_ip/ again. Your browser should show an error now, because you blocked remote access to the server.

Step 4 — Configuring Traffic Server as a Reverse Proxy

In this step, we will configure Traffic Server as a reverse proxy. To do so, open remap.config, which is the file you should edit to define Traffic Server’s mapping rules.

  1. sudo nano /etc/trafficserver/remap.config

Let’s create a simple rule that says all requests to the server’s IP address on port 8080 are mapped to the web server’s local address and port. You can do so by adding the following line to the end of the file:

remap.config
map http://your_server_ip:8080/ http://127.0.0.1:80/

Save the file and exit.

To activate the new mapping rule, use the reread_config command of traffic_line:

  1. sudo traffic_line --reread_config

Open a browser and visit http://your_server_ip:8080/. If you are able to see Apache’s welcome page now, you have successfully configured Traffic Server as a reverse proxy.

Step 5 — Configuring Traffic Server to Cache Everything

By default, Traffic Server will cache an HTTP response only if it contains a Cache-Control or Expires header explicitly specifying how long the item should be stored in the cache. However, as our web server is only serving static files, it is safe to cache all its responses.

To configure Traffic Server such that it caches all HTTP responses, you should change the value of a config variable called proxy.config.http.cache.required_headers to 0. This can be done using the set_var command of traffic_line.

  1. sudo traffic_line --set_var proxy.config.http.cache.required_headers --value 0

Apply the change using the reread_config flag.

  1. sudo traffic_line --reread_config

Open a browser and visit http://your_server_ip:8080/ again. This will store the Apache welcome page in Traffic Server’s cache.

Step 6 — Inspecting the Cache

To view the contents of Traffic Server’s cache, you can use a tool called Cache Inspector, which has a web-based interface.

To activate the tool, set the value of the proxy.config.http_ui_enabled config variable to 1.

  1. sudo traffic_line --set_var proxy.config.http_ui_enabled --value 1

Next, create a mapping rule specifying the path you want to use to access it. Open remap.config again using nano.

  1. sudo nano /etc/trafficserver/remap.config

Let’s make the Cache Inspector available on /inspect. To do so, add the following line at the top of the file:

remap.config
  1. map http://your_server_ip:8080/inspect http://{cache}

Save the file and exit.

To apply the changes, restart Traffic Server.

  1. sudo service trafficserver restart

The Cache Inspector is now ready to be used. Open a browser, and visit http://your_server_ip:8080/inspect/. You will see a page which looks like this:

Cache Inspector's home page

Next, click on the Lookup url link.

You can now type in a URL in the text field and click on the Lookup button to check if it is stored in the cache.

For example, you can type in http://your_server_ip:8080/ to check if your web server’s homepage is being served from the cache. If it is, you will see a page which looks like this:

Cached document details

Conclusion

You now know how to install Apache Traffic Server on Ubuntu 14.04 and configure it as a caching reverse-proxy. Though we used Apache as the web server in this tutorial, you can just as easily use any other web server. To learn more about Traffic Server, you can go through its Administrator’s Guide.

Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.

Learn more about our products

About the authors
Default avatar
Hathy A

author


Default avatar

staff technical writer

hi! i write do.co/docs now, but i used to be the senior tech editor publishing tutorials here in the community.


Still looking for an answer?

Ask a questionSearch for more help

Was this helpful?
 
3 Comments


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Hi there! Is this still working for you guys? Just wanna know, i follow the step but i encountered something wrong

i tried to apply this for streaming (set up proxy server between end viewer and the main source server) however it works (not 100% but usually ok) for vod but not for live channels… thanks to help with this…

So can we change the port 8080 that traffic server use to port 80 ?

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Join the Tech Talk
Success! Thank you! Please check your email for further details.

Please complete your information!

Become a contributor for community

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and SMBs

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

New accounts only. By submitting your email you agree to our Privacy Policy

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.