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 the dashboard, on the top menu, click Products and select Cloud Servers.
-
Go to Balancers → Balancers tab.
-
Open the balancer page.
-
Open the rule card.
-
Click Add New Policy.
-
Select the parameter by which to validate the request:
HOSTNAME
for the domain name orPATH
to validate the path. -
Select the type of match to the reference value:
EQUAL TO
— match;STARTS WITH.
— begins with;ENDS WITH.
— ends with;CONTAINS
— Contains;REGEX
— regular expression.
-
Enter a control value to check. If you selected the
REGEX
condition in step 7, enter a regular expression. -
Optional: To add another condition to the policy, click New Condition and customize it. If there are multiple conditions in the policy, the request must match each of them to fall under the policy.
-
Specify where to redirect the matching request:
- Direct to a target group — select a target group or create a new one with the HTTP protocol;
- URL redirect — 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 URL requests. For example, if you enter
https://example.com/new
, then the request tohttps://example.com/api
will be forwarded tohttps://example.com/new/api
To not accept requests that match the policy, select Deny Traffic.
-
Enter a policy name or leave the default one generated.
-
Click Add.
-
Create an 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
— redirect to the target group,REJECT
— REJECT;
-
<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
. Specify 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 with the commandopenstack loadbalancer pool list
. If you don't have a target group yet, create one.
-
--position <position>
— position of the policy in the rule. Specify if there will be multiple policies with the same action in the rule, the policy with position1
will be applied first; -
<listener>
— The ID or name of the rule. The list can be viewed with the commandopenstack 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
— match;STARTS WITH.
— begins with;ENDS WITH.
— ends with;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 you created in step 2.
-