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.
Control panel
OpenStack CLI
-
In the control panel, in the top menu, click Products and select Cloud Servers.
-
Go to Load Balancers → the Load Balancers tab.
-
Open the load balancer page.
-
Click Create rule.
-
Select the traffic reception protocol — HTTPS. The standard port 443 will be automatically selected, on which the load balancer will listen for traffic.
-
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.
-
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.
-
Select the HTTP request headers that will be forwarded to the servers.
-
Create an HTTP policy according to which traffic will be balanced. To do this, click Add new policy.
-
To balance requests by domain name, select the check condition: HOSTNAME — EQUAL TO.
-
Enter the domain name without protocol, for example,
example.com. -
Click New condition.
-
To balance requests by path, select the check condition: PATH — STARTS WITH.
-
Enter the text that the request path must start with, for example,
/api. -
Select the action Route to target group.
-
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.
-
Optional: change the policy name or leave the one generated by default.
-
Click Add.
-
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.
-
Click Create.