NSX-v Load Balancer Application Rules
Application rules in NSX for vSphere allow you to create advanced load balancing rules which may not be possible with the application profile or services natively available on the Edge Services Gateway (ESG). However, the ESG enables you to add your specific application rules to support your load balancing scenario; application rules are built using HA Proxy syntax.
In the code snippets below, I have included two of the HA Proxy snippets that I have deployed and used on the ESG.
Redirect to another pool
Redirect traffic to another load balancer pool if the primary pool is down. This takes into account that multiple pools are configured on the load-balancer and that all members in the primary pool are down. The only caveat here, is you must specify the Name and not the Pool ID, so be sure to copy it exactly from the Pools configuration pane.
1acl pool_down nbsrv(PRIMARY_POOL_NAME) eq 0 2use_backend SECONDARY_POOL_NAME if PRIMARY_POOL_NAME
Redirect to external website
Redirect traffic to a external website in the event that all members in the primary pool are down. You may elect to create a static maintenance page such as “site down for maintenance” whilst you bring up the pool members behind the load balancer.
1acl pool_down nbsrv(NAME_OF_POOL) eq 0 2redirect location http://www.tonysangha.com if pool_down
This post assumes that you have already completed the required steps to setup your application profile, virtual server and monitoring profiles. The only thing you are required to do after creating the application rules is to attach them to the virtual server you want them to be applied to, after which point they are in effect.