load balancing - HAProxy rewrite HTTP requests based on HTTP method -


i have rest api.

for sake of simplicity lets have 2 services:

  • read.request.com
  • write.request.com

how can rewrite read requests (get method) read.request.com , write requests (post, put, delete methods) write.request.com haproxy?

not quite sure of these applicable situation 1 is.

one backend

i think situation.

frontend http-in     bind *:80      acl is_post method post     acl is_get  method      http-request set-header host write.request.com if is_post     http-request set-header host read.request.com if is_get      default_backend api  backend api     server 1 localhost:8080 check 

all check method being used , sets host header accordingly before passing request on localhost:8080.

two backends

in set have have 1 instance of code running read requests , instance write requests. in case read code running on localhost:8080 , write code running on localhost:8081.

frontend http-in     bind *:80      acl is_post method post     acl is_get  method      use_backend write if is_post     use_backend read  if is_get  backend write     http-request set-header host write.request.com   #optional     server write_one localhost:8081 check  backend read     http-request set-header host read.request.com    #optional     server read_one localhost:8080 check 

this option starts same previous 1 checking method being used instead of using 1 haproxy backend splits out two. http-request line inside each backend optional configuration.

hope helps.


Comments

Popular posts from this blog

SVG stroke-linecap doesn't work for circles in Firefox? -

routes - Laravel 4 Wildcard Routing to Different Controllers -

cross browser - XSLT namespace-alias Not Working in Firefox or Chrome -