HAProxy Enterprise Documentation 2.1r1

Overview

A map file is a text file that often has the file extension .map, such as redirect_urls.map. HAProxy Enterprise will read map files during startup and load their contents into memory. After startup, it will not read the file again.

Maps help simplify complicated configuration files. For example, consider this verbose configuration that uses five use_backend lines to route traffic in different directions depending on the URL path:

frontend www
   bind :80
   use_backend cart_api if { path_beg /cart/ }
   use_backend reviews_api if { path_beg /reviews/ }
   use_backend products_api if { path_beg /products/ }
   use_backend login_api if { path_beg /login/ }
   use_backend chat_servers if { path_beg /chat/ }
   default_backend webservers

You can simplify this by using a map file. In the file, the path would be the key and the backend to use would be the value:

key

value

/cart/

cart_api

/reviews/

reviews_api

/products/

products_api

/login/

login_api

/chat/

chat_servers

Then, you could use the map_beg converter to lookup a key in the map and get its value. In the example below, we pass the requested URL path to the converter, which checks whether any of the keys in the map match the beginning of the requested path. If yes, that key's value is returned and used to complete the use_backend line:

frontend www
   bind :80
   use_backend %[path,map_beg(/etc/hapee-2.1/routes.map)]
   default_backend webservers

Next up

Syntax