Create HTTP policy
The number of HTTP policies in a rule and the number of conditions in an HTTP policy are unlimited.
Control panel
OpenStack CLI
-
In control panel go to Cloud platform → Balancers.
-
Open the tab Balancers → balancer page.
-
Open the rule card.
-
Click Add a new policy.
-
Select the parameter for which the query will be checked:
HOSTNAME
for the domain name orPATH
to check the path. -
Select the type of match to the reference value:
EQUAL TO
— is a match;STARTS WITH
— begins with;ENDS WITH
— ends in;CONTAINS
— contains;REGEX
— regular expression.
-
Enter a control value to check. If you selected the condition in step 6
REGEX
, enter a regular expression. -
Optional: to add another condition to the policy, press New condition and customize it. If there are multiple conditions in the policy, the request must match each condition to fall under the policy.
-
Specify where to redirect the matching request:
- Direct to the target group — select a target group or create a new with the HTTP protocol;
- Redirect to URL — enter a target URL that will completely replace the request URL, including protocol, domain name, path, and request parameters;
- Redirect to URL prefix — enter the part of the URL to replace the protocol and domain name in the request URL. For example, if you enter
https://example.com/new
then the request forhttps://example.com/api
will be forwarded tohttps://example.com/new/api
To not accept requests that match the policy, select Reject traffic.
-
Enter a policy name or leave the default one generated.
-
Click Add.
-
Create HTTP policy in the rule:
openstack loadbalancer l7policy create \
--action <action> \
[--redirect-url <url> | --redirect-prefix <prefix_url> | --redirect-pool <pool> ]
--position <position> \
--name <policy_name> \
<listener>Specify:
-
<action>
— action to balance traffic:REDIRECT_TO_URL
— completely replace the request URL, including protocol, domain name, path, and parameters;REDIRECT_PREFIX
— replace the protocol and domain name in the request URL;REDIRECT_TO_POOL
— to target the target group,REJECT
— dismiss;
-
<policy_name>
— L7-policy name; -
where the traffic needs to be directed:
--redirect-url <url>
— the full URL for the redirect. Specify if the action is selectedREDIRECT_TO_URL
;--redirect-prefix <prefix_url>
— URL prefix to replace the protocol and domain in the request, e.g.https://example.com
. Indicate if the action is selectedREDIRECT_PREFIX
;--redirect-pool <pool>
— ID or name of the target group. Specify if the action is selectedREDIRECT_TO_POOL
. The list can be viewed withopenstack loadbalancer pool list
. If you don't already have a target group, create it.
-
--position <position>
— the position of the policy in the rule. Indicate if there will be more than one policy with the same action in the rule, the policy with position1
will be the first to apply; -
<listener>
— ID or name of the rule. The list can be viewed withopenstack loadbalancer listener list
-
-
Create a condition in the HTTP policy:
openstack loadbalancer l7rule create \
--compare-type <compare_type> \
--type <type> \
--value <value> \
<policy>Specify:
-
<compare_type>
— type of match with the control value:EQUAL TO
— is a match;STARTS WITH
— begins with;ENDS WITH
— ends in;CONTAINS
— contains;REGEX
— regular expression;
-
<type>
— parameter in the query to check:HOST_NAME
,PATH
,COOKIE
,FILE_TYPE
,HEADER
; -
<value>
— control value; -
<policy>
— The ID or name of the L7 policy that you created in step 2.
-