Featured resource
Tech Upskilling Playbook 2025
Tech Upskilling Playbook

Build future-ready tech teams and hit key business milestones with seven proven plays from industry leaders.

Learn more
  • Labs icon Lab
  • Cloud
Google Cloud Platform icon
Labs

Using HTTP Rewrites with HAProxy

Wouldn’t it be great if we could manage all our HTTP requests, all in one place? HAProxy has the power to implement HTTP rewrites, changing the request as it moves between the client and the backend servers, transparently. In this hands-on lab, we’re going to get hands-on with HAProxy, using it to configure and test a basic HTTP rewrite. We’re also going to consolidate 2 HTTP `frontends` into 1, using access control lists (ACLs) to direct traffic to the correct `backend`, based on request hostname. Upon completion of this lab, you will be able to configure an HAProxy installation to implement a basic HTTP rewrite as well as implement HAProxy ACLs.

Google Cloud Platform icon
Labs

Path Info

Level
Clock icon Intermediate
Duration
Clock icon 30m
Last updated
Clock icon Aug 26, 2025

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.

Table of Contents

  1. Challenge

    Create a Rewrite and Some ACLs

    We're going to create a new subdirectory on the site, /textfiles and move our test.txt file there. We will handle requests for the file in its original location, /test.txt, using an HTTP rewrite in HAProxy.

    Perform the following:

    • Start by creating the new /usr/share/nginx/html/textfiles directory in each container using the podman exec command.
    • Next, we'll move the test.txt file to the /textfiles subdirectory.
    • Check your work by opening a bash shell in one container using podman exec.
      • Check the contents of the /usr/share/nginx/html directory.
      • Check the contents of /usr/share/nginx/html/textfiles.
      • Exit the container.
    • Perform the following checks with curl:
      • http://127.0.0.1:8000/test.txt
      • http://127.0.0.1:8100/test.txt
      • http://127.0.0.1:8000/textfiles/test.txt
      • http://127.0.0.1:8100/textfiles/test.txt
      • The first 2 will fail, the second 2 should work.
    • Add a rewrite to each of the frontends in the HAProxy configuration file that looks for requests for files that end in .txt and sets the path for those requests to /textfiles/.
      • Restart the haproxy service.
      • Perform the following checks with curl:
        • http://127.0.0.1:8000/test.txt
        • http://127.0.0.1:8100/test.txt
        • http://127.0.0.1:8000/textfiles/test.txt
        • http://127.0.0.1:8100/textfiles/test.txt
        • All checks should work now.
  2. Challenge

    Consolidate the HTTP Frontends Using ACLs

    We're going to replace the 2 HTTP frontends with a single frontend, using ACLs, so that requests for www.site1.com are directed to the site1 backend, and requests for www.site2.com are directed to the site2 backend.

    Perform the following:

    • Consolidate the 2 frontends into a single http frontend.
      • Bind the frontend to port 80 for all addresses.
      • Keep the current rewrites.
      • Add an ACL for each site, so that requests for www.site1.com are directed to the site1 backend, and requests for www.site2.com are directed to the site2 backend.
      • Leave the 2 backends untouched.
      • Restart the haproxy service.
      • Perform the following checks with curl:
        • http://www.site1.com/test.txt
        • http://www.site2.com/test.txt

Pluralsight Skills gives leaders confidence they have the skills needed to execute technology strategy. Technology teams can benchmark expertise across roles, speed up release cycles and build reliable, secure products. By leveraging our expert content, skill assessments and one-of-a-kind analytics, keep up with the pace of change, put the right people on the right projects and boost productivity. It's the most effective path to developing tech skills at scale.

What's a lab?

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Provided environment for hands-on practice

We will provide the credentials and environment necessary for you to practice right within your browser.

Guided walkthrough

Follow along with the author’s guided walkthrough and build something new in your provided environment!

Did you know?

On average, you retain 75% more of your learning if you get time for practice.