Skip to main content

Load balance traffic by request URL

You can route traffic to different target groups of servers depending on the domain and path specified in the request.

  1. In the control panel, in the top menu, click Products and select Cloud Servers.

  2. Go to Load Balancers → the Load Balancers tab.

  3. Open the load balancer page.

  4. Click Create rule.

  5. Select the traffic reception protocol — HTTPS. The standard port 443 will be automatically selected, on which the load balancer will listen for traffic.

  6. Select a certificate to terminate HTTPS traffic on the load balancer: select a certificate from Secret Manager or upload a new one. If the rule will accept traffic for multiple domains, the certificate must apply to all domains, or add multiple certificates.

  7. Select the default target group — traffic that does not match HTTP policies will be routed there. Select a group from the list or create a new target group, specify HTTP as its traffic destination protocol and port 80. If you want to drop traffic that does not match the HTTP policy, select No target group.

  8. Select the HTTP request headers that will be forwarded to the servers.

  9. Create an HTTP policy according to which traffic will be balanced. To do this, click Add new policy.

  10. To balance requests by domain name, select the check condition: HOSTNAME — EQUAL TO.

  11. Enter the domain name without protocol, for example, example.com.

  12. Click New condition.

  13. To balance requests by path, select the check condition: PATH — STARTS WITH.

  14. Enter the text that the request path must start with, for example, /api.

  15. Select the action Route to target group.

  16. Select the target group where traffic matching the policy will be routed. To create a new target group, click New target group and create a target group with the HTTP protocol and port 80. If you want to drop traffic that does not match the HTTP policy, select No target group.

  17. Optional: change the policy name or leave the one generated by default.

  18. Click Add.

  19. Optional: open the Advanced rule settings block and specify connection settings:

    • for incoming requests to the load balancer — specify the connection timeout and maximum number of connections;
    • for requests from the load balancer to servers — specify the connection timeout, inactivity timeout, and TCP packet wait timeout.
  20. Click Create.