0

I want to know if there's a way to balance the traffic within directories using haproxy.

I have haproxy balancing all HTTP traffic to server1 & server2. What I want is to balance all images directory requests to server1

e.g.

url: http://www.domain.com/images/image_one.jpg
url: http://www.domain.com/images/image_two.jpg
url: http://www.domain.com/images/image_three.jpg

All this requests must go to server1.

tachomi
  • 255
  • 3
  • 11

2 Answers2

2

You could declare an acl and then do a conditional use_backend statement. Like this:

frontend a-frontend-conf

    # Declare an ACL using path_beg (Path Begins)
    acl path_images path_beg /images

    # Use backend server1 if acl condition path_images is fulfilled
    use_backend server1 if path_images

backend server1
    [...]
Bazze
  • 1,531
  • 10
  • 11
1

Another way, assuming you already have a backend defined for server1 & server2, would be to do the static server selection in the backend, thusly:

frontend a-frontend-conf

    # Declare an ACL using the 'Host' header
    acl host_domain hdr(host) -i www.domain.com
    # Use backend 'farm' if acl condition host_domain is fulfilled
    use_backend farm if host_domain 

backend farm
    acl path_images path_beg /images
    use-server server1 if path_images
    server server1 1.1.1.1:80 
    server server2 2.2.2.2:80
GregL
  • 9,370
  • 2
  • 25
  • 36