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

Creating Load Balancing rules


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.

Create a Load Balancing rule in the Cloudflare dashboard via the following:

  1. Create a new rule
  2. Build an expression for the rule
  3. Save the rule and the load balancer configuration

Create a new Load Balancing rule

  1. Log in to your Cloudflare Account and click the site to manage.

  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 that specific load balancer. Otherwise, click Create Load Balancer and follow the workflow in Create a load balancer in the Cloudflare dashboard.

    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 appears, supply a descriptive name via the Rule name input. The example below uses "Select pool by URI path and query."

    Screenshot, Create Custom Rule dialog

After creating a rule, build a Load Balancing expression that defines when the rule triggers.

Build a Load Balancing expression

  1. In the Create Custom Rule Expression builder, under When incoming requests match…, use the Field drop-down list to choose an HTTP property. This example uses URI path. For more details, 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, Value is a drop-down list. Otherwise, Value is a text input. The example below 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. The below 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. Continue editing the expression as necessary.

  6. Choose a Load Balancing action of either Respond with fixed response or Override a current Load Balancer setting when the rule matches.

  7. [Optional] Click Add another action.

After configuring a Load Balancing action, save the Load Balancing rule and configuration.

Save a Load Balancing rule and configuration

  1. In the Create Custom Rule dialog, click Deploy. If unready to deploy your rule, click Save as draft.

    The Custom Rules card displays, and your 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 save completes, the Load Balancing page displays.