Skip to content
Load Balancing
Visit Load Balancing on GitHub
Set theme to dark (⇧+D)

Creating Load Balancing rules

Overview

You create and manage Load Balancing rules in the Custom Rules page, which is part of the Create/Edit Load Balancer workflow in the Traffic app.

To create a Load Balancing rule in the Cloudflare dashboard, follow this workflow:

  1. Create a new Load Balancing rule.
  2. Build an expression for the rule.
  3. Configure an action.
  4. Save the rule and the load balancer configuration.

Create a new Load Balancing rule

  1. Log in to your Cloudflare Account Home and click the site you want to manage in the dashboard.

  2. In the Cloudflare dashboard, click the Traffic app, then select the Load Balancing tab.

    Load Balancing tab in the Traffic app

  3. To add a rule to an existing load balancer, click the Edit link associated with the load balancer you want to manage:

    Edit load balancer link

    Otherwise, click Create Load Balancer and follow the workflow in Create a load balancer in the Cloudflare dashboard.

    When you click Edit, the Edit Load Balancer page displays:

    Edit Load Balancer page in Traffic app

  4. In the breadcrumb links for the Edit Load Balancer workflow, click Custom Rules.

    The Custom Rules card displays: Edit Load Balancer page in Traffic app

  5. Click Create Custom Rule.

  6. In the Create Custom Rule dialog that displays, use the Rule name input to supply a descriptive name. This example uses "Select pool by URI path and query."

    Screenshot, Create Custom Rule dialog

Now that you have created a rule and named it, continue to the next section and build a Load Balancing expression that defines when to trigger your rule.


Build a Load Balancing expression

  1. In the Expression builder in the Create Custom Rule dialog, under When incoming requests match…, use the Field drop-down list to choose an HTTP property. This example uses URI path. For more, see Supported fields and operators.

    Screenshot, Create Custom Rule dialog, choose Field

  2. To select a comparison operator, use the Operator drop-down list. This example uses the contains operator.

  3. Enter the value to match. When the field represents an enumeration, the Value control will be a drop-down list. Otherwise, it will be a text input. This example matches requests where the URI path contains /content:

    Screenshot, Create Custom Rule dialog, choose Value

  4. [Optional] To create a compound expression using logical operators, click the And or Or button.

    A new expression displays. Edit the expression. This example uses the and operator and adds the requirement that the URI query string contain webserver:

    Screenshot, Create Custom Rule dialog, add logical operator

  5. Edit the expression as desired.

Now that you have built an expression, continue to the next section and configure a Load Balancing action for the rule.


Configure a Load Balancing action

  1. To set an action for a rule, use the Action drop-down list. This example selects the Pool selection action:

    Screenshot, Create Custom Rule dialog, choose action

    The configuration options for the selected action display:

    Screenshot, Create Custom Rule dialog, choose action

  2. [Optional] Click Add another action.

Now that you have configured a Load Balancing action, continue to the next section and save the Load Balancing rule and configuration.


Save a Load Balancing rule and configuration

  1. In the Create Custom Rule dialog, click Deploy. If you are not ready to deploy the rule, click Save as draft.

    The Custom Rules card displays, and the new rule is listed:

    Screenshot, Custom Rules list

  2. Click Next and review your changes:

    Screenshot, Edit Load Balancer, Review

  3. Click Save.

When the operation is complete, the Load Balancing page displays.