How to configure HAProxy to send GET and POST HTTP requests to two different application servers

做~自己de王妃 提交于 2019-12-01 14:00:24

问题


I am using RESTful architecture. I have two application servers running. One should serve only GET request and other should serve only POST request. I want to configure HAProxy to loadbalance the requests depending upon the above condition. Please help me


回答1:


Here's a partial HAProxy configuration which can do this for you:

frontend webserver
  bind :80
  mode http
  acl is_post method POST
  use_backend post_app if is_post
  default_backend get_app

backend post_app
  mode http
  option forwardfor
  balance source
  option httpclose
  option httpchk HEAD / HTTP/1.0
  server post_app1 172.16.0.11:80 weight 1 check inter 1000 rise 5 fall 1
  server post_app2 172.16.0.12:80 weight 1 check inter 1000 rise 5 fall 1
  server post_app3 172.16.0.13:80 weight 1 check inter 1000 rise 5 fall 1 backup

backend get_app
  mode http
  option forwardfor
  balance source
  option httpclose
  option httpchk HEAD / HTTP/1.0
  server get_app1 172.16.0.21:80 weight 1 check inter 1000 rise 5 fall 1
  server get_app2 172.16.0.22:80 weight 1 check inter 1000 rise 5 fall 1
  server get_app3 172.16.0.23:80 weight 1 check inter 1000 rise 5 fall 1 backup


来源:https://stackoverflow.com/questions/5673335/how-to-configure-haproxy-to-send-get-and-post-http-requests-to-two-different-app

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!