HAProxy Enterprise Documentation 1.9r1

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

backend cart_api
   server s1 192.168.50.20:80

backend reviews_api
   server s1 192.168.50.21:80

backend products_api
   server s1 192.168.50.22:80

backend login_api
   server s1 192.168.50.23:80

backend chat_servers
   server s1 192.168.50.24:80

backend webservers
   server s1 192.168.50.25:80

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-1.9/routes.map)]
   default_backend webservers

backend cart_api
   server s1 192.168.50.20:80

backend reviews_api
   server s1 192.168.50.21:80

backend products_api
   server s1 192.168.50.22:80

backend login_api
   server s1 192.168.50.23:80

backend chat_servers
   server s1 192.168.50.24:80

backend webservers
   server s1 192.168.50.25:80

Next up

Syntax