page-rule

This command corresponds to the functions on the page of page rules.

Usage: oredge page-rule ACTION [OPTIONS]

ACTION:
    create
    list
    show
    modify
    delete

GLOBAL OPTIONS:
    --help
    --show-api                         print restful api request.
    --json                             print json format.
    --config                           specify config file, default is ~/.oredge/config.

Create a page rule

Usage: oredge rule create [http] [OPTIONS]

OPTIONS:
    --http string                      application http id.
    --action json                      action, can add multiple times.
    --cache json                       cache.
    --comment string                   comment.
    --condition json                   condition, can add multiple times.
    --content json                     content.
    --last bool                        last, true or false.
    --order integer                    order.
    --proxy json                       proxy.
    --waf json                         waf.

GLOBAL OPTIONS:
    --help
    --show-api                         print restful api request.
    --json                             print json format.
    --config                           specify config file, default is ~/.oredge/config.

For how to specify a page rule, check rule definition part.

Arguments definition

--http "http id"

Specify to which HTTP application the rule is created.

You can specify it in two method

    oredge rule create 1

or

    oredge rule create --http 1

--comment "description string"

You can add a description to this rule

--condition "json string"

This parameter can be used to add multiple conditions to hit the rule.

The condition is a json string. Check the detailed description and examples.

--action "json string"

This parameter can be used to add multiple actions to the request.

The action is a json string. Check the detailed description and examples.

--last "true"

Skip any subsequent page rules when this rule matches, default is false.

--order position

The order of the rule

--content "json"

This parameter set the static content of the rule.

Example:

> oredge create page-rule 1 --content '{"content":{"favicon":12}}'

ID: 1-1

--cache "json"

This parameter configure the cache of the rule. Check the detailed description and examples.

--proxy "json string"

This parameter can be used to add proxy to the specified upstream. The proxy is a json string.

Check the detailed description and examples.

--waf "json string"

This parameter can be used to add waf configuration of the rule.

The waf is a json string.

Example:

oredge create page-rule 1 --waf '{"rule_sets":[6,8,14,15],"action":"log","threshold_score":100}' \
    --condition '{"variable":{"name":"uri"},"operator":{"name":"eq"},"values":[{"type":"str","val":"/a/b"}]}'

List page rules

Usage: oredge rule list [http] [OPTIONS]

OPTIONS:
    --page integer                     page, 1(default).
    --page-size integer                page size, 20(default).
    --http integer                     http id.

GLOBAL OPTIONS:
    --help
    --show-api                         print restful api request.
    --json                             print json format.
    --config                           specify config file, default is ~/.oredge/config.

Example

# oredge rule list 892
ID          CREATE TIME            MODIFY TIME
892-1551    2021-07-15 07:09:59    2021-07-15 07:09:59

Get details of a page rule

Usage: oredge rule show [id] [OPTIONS]

OPTIONS:
    --id integer                       id.

GLOBAL OPTIONS:
    --help
    --show-api                         print restful api request.
    --json                             print json format.
    --config                           specify config file, default is ~/.oredge/config.

Example

# oredge rule show 892-1551
ID         : 892-1551
CREATE TIME: 2021-07-15 07:09:59
MODIFY TIME: 2021-07-15 07:09:59

Modify a page rule

Usage: oredge rule modify [id] [OPTIONS]

OPTIONS:
    --id integer                       id.
    --action json                      action, can add multiple times.
    --cache json                       cache.
    --comment string                   comment.
    --condition json                   condition, can add multiple times.
    --content json                     content.
    --last bool                        last, true or false.
    --order integer                    order.
    --proxy json                       proxy.
    --waf json                         waf.


GLOBAL OPTIONS:
    --help
    --show-api                         print restful api request.
    --json                             print json format.
    --config                           specify config file, default is ~/.oredge/config.

Example

# oredge rule modify 892-1551 --condition 'xxx'
OK

Delete a page rule

Usage: oredge rule delete [id] [OPTIONS]

OPTIONS:
    --id integer                       id.

GLOBAL OPTIONS:
    --help
    --show-api                         print restful api request.
    --json                             print json format.
    --config                           specify config file, default is ~/.oredge/config.

Example

# oredge rule delete 892-1551
OK

Rule definition

A page rule is basically constructed by a condition part and an action part.

Condition

A condition is formed by 3 parts, variable, operator, values. For example, a condition like var1 equals 3 has:

  • variable var1: this can be a user variable, or a global variable defined in advance, or you can choose one of the builtin variables list;
  • operator equals: choose one which suits your need in operators list
  • value 3: value part can be specified by type, check value definition

You can have multiple condition items.

nametyperequireddescription
variableobjectyessee variable definition
operatorobjectyessee operator definition
valuesarrayyesan array of value, see value definition
caselessboolyescase-insensitive

Variable definition

nametyperequireddescription
namestringnovariable name, see builtin variable list
user_varintegernouser variable id
global_varintegernoglobal variable id
argsstringnosome variables needs args, see builtin variable list

Note: only one of name, user_var, global_var must be set.

Builtin variable list

nameneed argsargsoperatorsdescription
urinoeq,ne,lt,le,gt,ge,contains,contains-word,prefix,suffix,!contains,!contains-word,!prefix,!suffixURI
uri-argyesstringeq,ne,lt,le,gt,ge,contains,contains-word,prefix,suffix,!contains,!contains-word,!prefix,!suffix,==,!=,<,<=,>,>=,is-empty,!is-emptyURI argument
uri-segyesintegereq,ne,lt,le,gt,ge,contains,contains-word,prefix,suffix,!contains,!contains-word,!prefix,!suffix,==,!=,<,<=,>,>=,is-empty,!is-emptyURI segment
query-stringnoeq,ne,lt,le,gt,ge,contains,contains-word,prefix,suffix,!contains,!contains-word,!prefix,!suffixQuery string
sorted-query-stringnoeq,ne,lt,le,gt,ge,contains,contains-word,prefix,suffix,!contains,!contains-word,!prefix,!suffixSorted URI argument
hostnoeq,ne,lt,le,gt,ge,contains,contains-word,prefix,suffix,!contains,!contains-word,!prefix,!suffixHost
req-methodnoeq,neRequest method
req-cookieyesstringeq,ne,lt,le,gt,ge,contains,contains-word,prefix,suffix,!contains,!contains-word,!prefix,!suffix,==,!=,<,<=,>,>=,is-empty,!is-emptyRequest cookie
req-headeryesstringeq,ne,lt,le,gt,ge,contains,contains-word,prefix,suffix,!contains,!contains-word,!prefix,!suffix,==,!=,<,<=,>,>=,is-empty,!is-emptyRequest header
schemenoeq,neScheme
server-portno==,!=,<,<=,>,>=Server Port
server-addrno~~,!~~,eq,ne,lt,le,gt,ge,contains,contains-word,prefix,suffix,!contains,!contains-word,!prefix,!suffixServer address
first-x-forwarded-addrno~~,!~~,eq,ne,lt,le,gt,ge,contains,contains-word,prefix,suffix,!contains,!contains-word,!prefix,!suffixFirst address in X-Forwarded-For
last-x-forwarded-addrno~~,!~~,eq,ne,lt,le,gt,ge,contains,contains-word,prefix,suffix,!contains,!contains-word,!prefix,!suffixLast address in X-Forwarded-For
user-agentnoeq,ne,lt,le,gt,ge,contains,contains-word,prefix,suffix,!contains,!contains-word,!prefix,!suffix,==,!=,<,<=,>,>=,is-empty,!is-emptyUser agent
User agent is mobilenois-true,!is-trueUser agent is mobile
client-continentyesstringeq,neClient continent
client-countryyesstringeq,neClient country/region
client-provinceyesstringeq,neClient provinces (China)
client-cityyesstringeq,neClient city
client-addrno~~,!~~,eq,ne,lt,le,gt,ge,contains,contains-word,prefix,suffix,!contains,!contains-word,!prefix,!suffixClient address
ssl-client-s-dnnoeq,ne,lt,le,gt,ge,contains,contains-word,prefix,suffix,!contains,!contains-word,!prefix,!suffix,==,!=,<,<=,>,>=,is-empty,!is-emptySSL Client Subject DN

Operator definition

nametyperequireddescription
namestringyesthe name of the operator, see operator list

Operator list

Different operator support different value types.

operatorvalue type
eqstr,rx,wc
nestr,rx,wc
ltstr
lestr
gtstr
gestr
containsstr,rx,wc
contains-wordstr,rx,wc
prefixstr,rx,wc
suffixstr,rx,wc
!containsstr,rx,wc
!contains-wordstr,rx,wc
!prefixstr,rx,wc
!suffixstr,rx,wc
==str
!=str
<str
<=str
>str
>=str
is-empty
!is-empty
is-true
!is-true
~~netaddr,ip-list
!~~netaddr,ip-list

Value definition

nametyperequireddescription
typestringyesstr,rx,wc,netaddr,uv,global-uv,ip-list, see operator list
valstringyes

Condition examples

  1. uri example
> oredge create page-rule 1 \
    --condition '{"variable":{"name":"uri"},"operator":{"name":"eq"},"values":[{"type":"str","val":"/a/b"}]}' \
    --action '{ "type": "set-uri", "set-uri": { "uri": "/foo/bar" } }'
ID: 1-1

  1. uri-arg example
> oredge create page-rule 1 \
    --condition '{"operator":{"name":"eq"},"variable":{"name":"uri-arg","args":"foo"},"values":[{"type":"str","val":"bar"}]}' \
    --action '{ "type": "set-uri", "set-uri": { "uri": "/foo/bar" } }'

ID: 1-1

  1. uri-seg example
> oredge create page-rule 1 \
    --condition '{"variable":{"name":"uri-seg","args":"1"},"operator":{"name":"eq"},"values":[{"type":"str","val":"foo"}]}' \
    --action '{ "type": "set-uri", "set-uri": { "uri": "/foo/bar" } }'

ID: 1-1

  1. query-string example
> oredge create page-rule 1 \
    --condition '{"variable":{"name":"query-string"},"operator":{"name":"prefix"},"values":[{"type":"str","val":"foo"}]}' \
    --action '{ "type": "set-uri", "set-uri": { "uri": "/foo/bar" } }'

ID: 1-1
  1. sorted-query-string example
> oredge create page-rule 1 \
    --condition '{"variable":{"name":"sorted-query-string"},"values":[{"type":"str","val":"foo"}],"operator":{"name":"prefix"}}' \
    --action '{ "type": "set-uri", "set-uri": { "uri": "/foo/bar" } }'

ID: 1-1
  1. host example
> oredge create page-rule 1 \
    --condition '{"variable":{"name":"host"},"values":[{"type":"str","val":"foo"}],"operator":{"name":"eq"},"caseless":true}' \
    --action '{ "type": "set-uri", "set-uri": { "uri": "/foo/bar" } }'

ID: 1-1
  1. req-method example
> oredge create page-rule 1 \
    --condition '{"operator":{"name":"eq"},"values":[{"type":"str","val":"GET"}],"caseless":false,"variable":{"name":"req-method"}}' \
    --action '{ "type": "set-uri", "set-uri": { "uri": "/foo/bar" } }'

ID: 1-1
  1. req-cookie example
> oredge create page-rule 1 \
    --condition '{"operator":{"name":"eq"},"values":[{"type":"str","val":"bar"}],"variable":{"name":"req-cookie","args":"foo"}}' \
    --action '{ "type": "set-uri", "set-uri": { "uri": "/foo/bar" } }'

ID: 1-1
  1. req-header example
> oredge create page-rule 1 \
    --condition '{"operator":{"name":"eq"},"values":[{"type":"str","val":"bar"}],"variable":{"name":"req-header","args":"foo"}}' \
    --action '{ "type": "set-uri", "set-uri": { "uri": "/foo/bar" } }'

ID: 1-1
  1. scheme example
> oredge create page-rule 1 \
    --condition '{"operator":{"name":"eq"},"values":[{"type":"str","val":"http"}],"variable":{"name":"scheme"}}' \
    --action '{ "type": "set-uri", "set-uri": { "uri": "/foo/bar" } }'

ID: 1-1
  1. server-port example
> oredge create page-rule 1 \
    --condition '{"operator":{"name":"=="},"values":[{"type":"str","val":"80"}],"variable":{"name":"server-port"}}' \
    --action '{ "type": "set-uri", "set-uri": { "uri": "/foo/bar" } }'

ID: 1-1
  1. server-addr example
> oredge create page-rule 1 \
    --condition '{"operator":{"name":"eq"},"values":[{"type":"str","val":"192.168.0.1"}],"variable":{"name":"server-addr"}}' \
    --action '{ "type": "set-uri", "set-uri": { "uri": "/foo/bar" } }'

ID: 1-1
  1. first-x-forwarded-addr example
> oredge create page-rule 1 \
    --condition '{"operator":{"name":"~~"},"values":[{"type":"netaddr","val":"192.168.0.1"}],"variable":{"name":"first-x-forwarded-addr"}}' \
    --action '{ "type": "set-uri", "set-uri": { "uri": "/foo/bar" } }'

ID: 1-1
> oredge create page-rule 1 \
    --condition '{"operator":{"name":"~~"},"values":[{"type":"ip-list","val":"15"}],"variable":{"name":"first-x-forwarded-addr"}}' \
    --action '{ "type": "set-uri", "set-uri": { "uri": "/foo/bar" } }'

ID: 1-1
  1. last-x-forwarded-addr example
> oredge create page-rule 1 \
    --condition '{"operator":{"name":"~~"},"values":[{"type":"netaddr","val":"192.168.0.1"}],"variable":{"name":"last-x-forwarded-addr"}}' \
    --action '{ "type": "set-uri", "set-uri": { "uri": "/foo/bar" } }'

ID: 1-1
> oredge create page-rule 1 \
    --condition '{"operator":{"name":"~~"},"values":[{"type":"ip-list","val":"15"}],"variable":{"name":"last-x-forwarded-addr"}}' \
    --action '{ "type": "set-uri", "set-uri": { "uri": "/foo/bar" } }'

ID: 1-1
  1. user-agent example
> oredge create page-rule 1 \
    --condition '{"operator":{"name":"eq"},"values":[{"type":"str","val":"foo"}],"variable":{"name":"user-agent"}}' \
    --action '{ "type": "set-uri", "set-uri": { "uri": "/foo/bar" } }'

ID: 1-1
  1. ua-is-mobile example
> oredge create page-rule 1 \
    --condition '{"operator":{"name":"is-true"},"variable":{"name":"ua-is-mobile"}}' \
    --action '{ "type": "set-uri", "set-uri": { "uri": "/foo/bar" } }'

ID: 1-1
> oredge create page-rule 1 \
    --condition '{"operator":{"name":"!is-true"},"variable":{"name":"ua-is-mobile"}}' \
    --action '{ "type": "set-uri", "set-uri": { "uri": "/foo/bar" } }'

ID: 1-1
  1. client-continent example
> oredge create page-rule 1 \
    --condition '{"operator":{"name":"eq"},"variable":{"name":"client-continent"},"values":[{"type":"str","val":"AF"}]}' \
    --action '{ "type": "set-uri", "set-uri": { "uri": "/foo/bar" } }'

ID: 1-1
  1. client-country example
> oredge create page-rule 1 \
    --condition '{"operator":{"name":"eq"},"values":[{"type":"str","val":"UK"}],"variable":{"name":"client-country"}}' \
    --action '{ "type": "set-uri", "set-uri": { "uri": "/foo/bar" } }'

ID: 1-1
  1. client-province example
> oredge create page-rule 1 \
    --condition '{"values":[{"type":"str","val":"Beijing"}],"operator":{"name":"eq"},"variable":{"name":"client-province"}}' \
    --action '{ "type": "set-uri", "set-uri": { "uri": "/foo/bar" } }'

ID: 1-1
  1. client-city example
> oredge create page-rule 1 \
    --condition '{"operator":{"name":"eq"},"values":[{"type":"str","val":"London"}],"variable":{"name":"client-city"}}' \
    --action '{ "type": "set-uri", "set-uri": { "uri": "/foo/bar" } }'

ID: 1-1
  1. client-addr example
> oredge create page-rule 1 \
    --condition '{"operator":{"name":"eq"},"values":[{"type":"str","val":"192.168.1.1"}],"variable":{"name":"client-addr"}}' \
    --action '{ "type": "set-uri", "set-uri": { "uri": "/foo/bar" } }'

ID: 1-1
  1. ssl-client-s-dn example
> oredge create page-rule 1 \
    --condition '{"operator":{"name":"eq"},"values":[{"type":"str","val":"foo.com"}],"variable":{"name":"ssl-client-s-dn"}}' \
    --action '{ "type": "set-uri", "set-uri": { "uri": "/foo/bar" } }'

ID: 1-1
  1. global user variable example
> oredge create page-rule 1 \
    --condition '{"operator":{"name":"eq"},"values":[{"type":"str","val":"foo"}],"variable":{"global_var":7}}' \
    --action '{ "type": "set-uri", "set-uri": { "uri": "/foo/bar" } }'

ID: 1-1
  1. gateway-cluster example
> oredge create page-rule 1 \
    --condition '{"operator":{"name":"eq"},"values":[{"type":"str","val":"1"}],"variable":{"name":"gateway-cluster"}}' \
    --action '{ "type": "set-uri", "set-uri": { "uri": "/foo/bar" } }'

ID: 1-1

Action

nametypedescription
typestringaction type
?objectthe name is equal to value of type,
for example {type: "set-uri", set-uri: {...}}

You can also use custom

Available builtin action list

set-uri

Set URI

nametypedescription
uristring

Example:

> oredge create page-rule 1 --action '{ "type": "set-uri", "set-uri": { "uri": "/foo/bar" } }'

ID: 1-1
add-uri-prefix

Add URI prefix

nametypedescription
valuestring

Example:

> oredge create page-rule 1 --action '{"type":"add-uri-prefix","add-uri-prefix":{"value":"/foo"}}'

ID: 1-1
rm-uri-prefix

Remove URI prefix

nametypedescription
valuestring

Example:

> oredge create page-rule 1 --action '{"type":"rm-uri-prefix","rm-uri-prefix":{"value":"/foo"}}'

ID: 1-1
rm-uri-seg

Remove URI segment

nametypedescription
valueinteger

Example:

> oredge create page-rule 1 --action '{"type":"rm-uri-seg","rm-uri-seg":{"index":1}}'

ID: 1-1
set-req-header

Set request header

nametypedescription
headerstring
valuestring

Example:

> oredge create page-rule 1 --action '{"type":"set-req-header","set-req-header":{"header":"foo","value":"bar"}}'

ID: 1-1
add-req-header

Add request header

nametypedescription
headerstring
valuestring

Example:

> oredge create page-rule 1 --action '{"type":"add-req-header","add-req-header":{"header":"foo","value":"bar"}}'

ID: 1-1
set-uri-arg

Set URI argument

nametypedescription
argstring
valuestring

Example:

> oredge create page-rule 1 --action '{"type":"set-uri-arg","set-uri-arg":{"arg":"foo","value":"bar"}}'

ID: 1-1
add-uri-arg

Add URI argument

nametypedescription
argstring
valuestring

Example:

> oredge create page-rule 1 --action '{"type":"add-uri-arg","add-uri-arg":{"arg":"foo","value":"bar"}}'

ID: 1-1
rm-uri-arg

Remove URI argument

nametypedescription
namestring

Example:

> oredge create page-rule 1 --action '{"type":"rm-uri-arg","rm-uri-arg":{"name":"foo"}}'

ID: 1-1
set-proxy-uri

Set proxy URI

nametypedescription
valuestring
argstring

Example:

> oredge create page-rule 1 --action '{"type":"set-proxy-uri","set-proxy-uri":{"uri":"/foo"}}'

ID: 1-1
rewrite-proxy-uri-prefix

Rewrite proxy URI prefix

nametypedescription
prefixstring
replacementstring

Example:

> oredge create page-rule 1 --action '{"type":"rewrite-proxy-uri-prefix","rewrite-proxy-uri-prefix":{"prefix":"/foo","replacement":"/bar"}}'

ID: 1-1
set-proxy-header

Set proxy header

nametypedescription
headerstring
valuestring
el_varstring

Example:

> oredge create page-rule 1 --action '{"type":"set-proxy-header","set-proxy-header":{"header":"Host","value":"foo"}}'

ID: 1-1
append-proxy-header-value

Append proxy header value

nametypedescription
headerstring
valuestring
el_varstring

Example:

> oredge create page-rule 1 --action '{"type":"append-proxy-header-value","append-proxy-header-value":{"el_var":"client-addr","header":"X-Forwarded-For"}}'

ID: 1-1
enable-proxy-cache-revalidate

Enable proxy cache revalidate

nametypedescription
enabledstring

Example:

> oredge create page-rule 1 --action '{"type":"enable-proxy-cache-revalidate","enable-proxy-cache-revalidate":{"enabled":true}}'

ID: 1-1
set-proxy-cache-use-stale

Use stale proxy cache

nametypedescription
valuestring

Example:

> oredge create page-rule 1 --action '{"type":"set-proxy-cache-use-stale","set-proxy-cache-use-stale":{"args":["error","timeout","invalid_header","updating","http_500","http_502","http_503","http_504","http_403","http_404","http_429"]}}'

ID: 1-1
redirect

Redirect

nametypedescription
argsstring
codestring
hoststring
portstring
schemestring
urlstring

Example:

> oredge create page-rule 1 --action '"type":"redirect","redirect":{"scheme":"http","port":80,"url":"/foo","args":"foo=bar","host":"foo.com","code":302}}'

ID: 1-1
print

Print

nametypedescription
content_typestring

Example:

> oredge create page-rule 1 --action '{"type":"print","print":{"msg":"<!doctype html>\n<html>\n<head>\n  <title>Response</title>\n</head>\n<body>\n</body>\n</html>","content_type":"text/html"}}'

ID: 1-1
exit

Exit

nametypedescription
codestring

Example:

> oredge create page-rule 1 --action '{"type":"exit","exit":{"code":204}}'

ID: 1-1
send-static-file

Return static file

nametypedescription
start_indexstring
end_indexstring

Example:

> oredge create page-rule 1 --action '{"type":"send-static-file","send-static-file":{"start_index":1,"end_index":2}}'

ID: 1-1
sleep

sleep

nametypedescription
timestring

Example:

> oredge create page-rule 1 --action '{"type":"sleep","sleep":{"time":2}}'

ID: 1-1
limit-req-rate

Limit request rate

nametypedescription
edge_captcha_clearance_timestring
error_page_status_codestring
hcaptcha_clearance_timestring
limit_keystring
rate_rejectstring
rate_reject_unitstring
rate_shapestring
rate_shape_unitstring
reject_actionstring

Example:

> oredge create page-rule 1 --action '{"type":"limit-req-rate","limit-req-rate":{"limit_key":"client-addr","rate_shape":1,"rate_shape_unit":"r/s","rate_reject":1,"rate_reject_unit":"r/s","reject_action":"error_page","error_page_status_code":503,"hcaptcha_clearance_time":60,"edge_captcha_clearance_time":60}}'

ID: 1-1
limit-req-count

Limit request count

nametypedescription
count_rejectstring
count_time_windowstring
limit_keystring

Example:

> oredge create page-rule 1 --action '{"type":"limit-req-count","limit-req-count":{"limit_key":"client-addr","count_reject":10,"count_time_window":1}}'

ID: 1-1
block-req

Block request

nametypedescription
block_thresholdstring
block_timestring
limit_keystring
observe_intervalstring
rate_rejectstring
rate_reject_unitstring
rate_shapestring
rate_shape_unitstring

Example:

> oredge create page-rule 1 --action '{"type":"block-req","block-req":{"limit_key":"client-addr","rate_shape":1,"rate_shape_unit":"r/s","rate_reject":1,"rate_reject_unit":"r/s","block_threshold":2,"observe_interval":5,"block_time":60}}'

ID: 1-1
set-resp-header

Set response header

nametypedescription
namestring
valuestring
el_var_argstring

Example:

> oredge create page-rule 1 --action '{"type":"set-resp-header","set-resp-header":{"name":"foo","value":"bar"}}'

ID: 1-1
add-resp-header

Add response header

nametypedescription
namestring
valuestring
el_var_argstring

Example:

> oredge create page-rule 1 --action '{"type":"add-resp-header","add-resp-header":{"name":"foo","value":"bar"}}'

ID: 1-1
rm-resp-header

Remove response header

nametypedescription
namestring

Example:

> oredge create page-rule 1 --action '{"type":"rm-resp-header","rm-resp-header":{"name":"foo"}}'

ID: 1-1
apply-std-mime-types
nametypedescription
forcebool

Example:

> oredge create page-rule 1 --action '{"type":"apply-std-mime-types","apply-std-mime-types":{"force":true}}'

ID: 1-1
expires
nametypedescription
forcebool
max_ageinteger
max_age_unitstring

Example:

> oredge create page-rule 1 --action '{"type":"expires","expires":{"max_age":1,"max_age_unit":"hour","force":true}}'

ID: 1-1
nametypedescription
el_var_argstring
http_onlyinteger
max_agestring
max_age_unitstring
namestring
pathstring
valuestring

Example:

> oredge create page-rule 1 --action '{"type":"set-resp-cookie","set-resp-cookie":{"http_only":true,"max_age":1,"max_age_unit":"hour","name":"foo","el_var":"userid","domain":"bar.com","path":"/foo/bar"}}'

ID: 1-1
limit-resp-data-rate
nametypedescription
ratestring
rate_unitinteger

Example:

> oredge create page-rule 1 --action '{"type":"limit-resp-data-rate","limit-resp-data-rate":{"rate_unit":"kB/s","rate":10}}'

ID: 1-1
user-code
nametypedescription
elstring

Example:

> oredge create page-rule 1 --action '{"type":"user-code","user-code":{"el":"my Str $s = \"hello world\";"}}'

ID: 1-1
enable-openidc-authentication
nametypedescription
client_idstring
client_secretstring
discoverystring
logout_pathstring
redirect_uristring
scopestring
ssl_verifystring
timeoutstring
timeout_unitstring
token_endpoint_auth_methodstring

Example:

> oredge create page-rule 1 --action '{"type":"enable-openidc-authentication","enable-openidc-authentication":{"token_endpoint_auth_method":"client_secret_basic","scope":"openid","ssl_verify":false,"timeout":1000,"timeout_unit":"ms","logout_path":"/logout","client_id":"foo","client_secret":"bar","discovery":"http://foo.com/a/b","redirect_uri":"http://foo.com/c/d"}}'

ID: 1-1
enable-websocket

Example:

> oredge create page-rule 1 --action '{"type":"enable-websocket","enable-websocket":{}}'

ID: 1-1
enable-gateway-brotli
nametypedescription
enabledbool

Example:

> oredge create page-rule 1 --action '{"type":"enable-gateway-brotli","enable-gateway-brotli":{"enabled":true}}'

ID: 1-1
enable-gateway-gzip
nametypedescription
enabledbool

Example:

> oredge create page-rule 1 --action '{"type":"enable-gateway-gzip","enable-gateway-gzip":{"enabled":true}}'

ID: 1-1
intercept-upstream-errors
nametypedescription
enabledbool

Example:

> oredge create page-rule 1 --action '{"type":"intercept-upstream-errors","intercept-upstream-errors":{"enabled":true}}'

ID: 1-1
errlog
nametypedescription
levelstring
msgstring

Example:

> oredge create page-rule 1 --action '{"type":"errlog","errlog":{"level":"error","msg":"foo"}}'

ID: 1-1
set-brotli-types
nametypedescription
typesarray

Example:

> oredge create page-rule 1 --action '{"type":"set-brotli-types","set-brotli-types":{"types":["foo", "bar"]}}'

ID: 1-1
set-gzip-types
nametypedescription
typesarray

Example:

> oredge create page-rule 1 --action '{"type":"set-gzip-types","set-gzip-types":{"types":["foo","bar"]}}'

ID: 1-1
set-max-body-size
nametypedescription
valueinteger
unitstring

Example:

> oredge create page-rule 1 --action '{"type":"set-max-body-size","set-max-body-size":{"value":1,"unit":"mB"}}'

ID: 1-1
set-var
nametypedescription
global_var_idinteger
valuestring

Example:

> oredge create page-rule 1 --action '{"type":"set-var","set-var":{"global_var_id":5,"value":"yes"}}'

ID: 1-1
set-error-page

Example:

> oredge create page-rule 1 --action '{"type":"set-error-page","set-error-page":{"type":"raw-content","content_type":"text/html; charset=utf8","content":"<!doctype html>\n<html lang=\"en\">\n<head>\n  <title>404 NOT FOUND</title>\n</head>\n<body>\n</body>\n</html>","status":[403,404,500,502,503,504]}}'

ID: 1-1
disable-req-buffering

Example:

> oredge create page-rule 1 --action '{"type":"disable-req-buffering","disable-req-buffering":{}}'

ID: 1-1
enable-basic-authentication

Example:

> oredge create page-rule 1 --action '{"type":"enable-basic-authentication","enable-basic-authentication":{"app_auth_id":3}}'

ID: 1-1
Using custom global action

You can apply predefined global action by specified the id.

> oredge create page-rule 1 --action '{"global_action_id":1}'

ID: 1-1

Cache

nametypedescription
browserCachebool
browser_ttlinteger
browser_ttl_unitstring
cluster_hashboolUse consistent hashing to share the response cache in each gateway cluster.
default_ttlsarray
cache_keyarraythe key of cache content, see cache key list
enableDefaultTtlboolWhen disabled (which is the default), we won’t cache responses without any cache controlling headers like Expires and Cache-Control. When enabled, we will cache these responses with force. If the backend servers explicitly disable caching, then the cache will still be bypassed even when this option is enabled.

Cache key list

nameneed args
urino
uri-argyes
uri-segyes
query-stringno
sorted-query-stringno
req-methodno
req-cookieyes
req-headeryes
schemeno
first-x-forwarded-addrno
last-x-forwarded-addrno
user-agentno
ua-is-mobileno
client-continentno
client-provinceno
client-cityno
client-ispno
ssl-client-s-dnno

Cache examples

> oredge create page-rule 1 --cache '{"cache_key":[{"name":"uri"},{"name":"query-string"},{"name":"uri-seg","args":"1"}],"enableDefaultTtl":true,"enforce_cache":false,"cluster_hash":true,"enableConvertHead":true,"enable_global":true,"browserCache":true,"browser_ttl":1,"browser_ttl_unit":"min","disable_convert_head":false,"default_ttls":[{"ttl":1,"ttl_unit":"min","status":200}]}' \
    --proxy '{"upstream":[{"cluster":1836,"weight":1,"upstream":null}],"backup_upstream":[],"upstream_el_code":"","balancer":{"algorithm":"roundrobin","variables":[]},"useSameBalancingPolicy":true,"sticky":{"enable":false,"key":"Edge-Sticky","level":"upstream","ttl":0,"mode":"none"},"retry_condition":["error","timeout","invalid_header","http_500","http_502","http_504"],"connect_timeout":6,"connect_timeout_unit":"s","send_timeout":6,"send_timeout_unit":"s","read_timeout":6,"read_timeout_unit":"s","retries":1,"layer_policy":null,"balancer2":null}'

Proxy

nametypedescription
balancerobjectbalancer algorithm
upstreamobject
backup_upstreamobject
upstream_el_codestringyou can use edgelang instead of upstream and backup_upstream
connect_timeoutinteger
connect_timeout_unitstrings,ms
read_timeoutinteger
read_timeout_unitstrings,ms
send_timeoutinteger
send_timeout_unitstrings,ms
layer_policyinteger
retriesintegerset to -1 means same as the number of upstream nodes.
retry_conditionarrayarray of string, value must be error,timeout,invalid_header,http_500,http_502,http_504
stickyobject

balancer

nametypedescription
algorithmstringone of hash,chash,roundrobin
variablesarrayif algorithm is hash or chash, this field is required.

Variables is an array of object. The object is like this: {"name" : "uri" } or {"name" : "uri-arg", "args" : "foo"} (for variable need arguments).

All available variables are listed here:

nameneed args
urino
uri-argyes
uri-segyes
query-stringno
sorted-query-strinno
req-methodno
req-cookieyes
req-headeryes
schemeno
first-x-forwarded-addrno
last-x-forwarded-addrno
user-agentno
ua-is-mobileno
client-continentno
client-provinceno
client-cityno
client-ispno
ssl-client-s-dnno

upstream

nametypedescription
clusterintegerupstream id
global_clusterintegerglobal upstream id
k8s_clusterintegerk8s upstream id
global_k8s_clusterintegerglobal k8s upstream id
weightintegerweight of the upstream

sticky

nametypedescription
enablebool
keystring
levelstringupstream,server
ttlinteger

Proxy examples

  1. proxy a upstream
> oredge create page-rule 1 --proxy '{"upstream":[{"cluster":1836,"weight":1}],"backup_upstream":[],"upstream_el_code":"","balancer":{"algorithm":"roundrobin","variables":[]},"useSameBalancingPolicy":true,"sticky":{"enable":false,"key":"Edge-Sticky","level":"upstream","ttl":0,"mode":"none"},"retry_condition":["error","timeout","invalid_header","http_500","http_502","http_504"],"connect_timeout":6,"connect_timeout_unit":"s","send_timeout":6,"send_timeout_unit":"s","read_timeout":6,"read_timeout_unit":"s","retries":1,"layer_policy":null,"balancer2":null}' \
    --condition '{"variable":{"name":"uri"},"operator":{"name":"eq"},"values":[{"type":"str","val":"/a/b"}]}'

  1. proxy a global upstream
> oredge create page-rule 1 --proxy '{"upstream":[{"global_cluster":1836,"weight":1}],"backup_upstream":[],"upstream_el_code":"","balancer":{"algorithm":"roundrobin","variables":[]},"useSameBalancingPolicy":true,"sticky":{"enable":false,"key":"Edge-Sticky","level":"upstream","ttl":0,"mode":"none"},"retry_condition":["error","timeout","invalid_header","http_500","http_502","http_504"],"connect_timeout":6,"connect_timeout_unit":"s","send_timeout":6,"send_timeout_unit":"s","read_timeout":6,"read_timeout_unit":"s","retries":1,"layer_policy":null,"balancer2":null}' \
    --condition '{"variable":{"name":"uri"},"operator":{"name":"eq"},"values":[{"type":"str","val":"/a/b"}]}'

  1. proxy a k8s upstream
> oredge create page-rule 1 --proxy '{"upstream":[{"k8s_cluster":1836,"weight":1}],"backup_upstream":[],"upstream_el_code":"","balancer":{"algorithm":"roundrobin","variables":[]},"useSameBalancingPolicy":true,"sticky":{"enable":false,"key":"Edge-Sticky","level":"upstream","ttl":0,"mode":"none"},"retry_condition":["error","timeout","invalid_header","http_500","http_502","http_504"],"connect_timeout":6,"connect_timeout_unit":"s","send_timeout":6,"send_timeout_unit":"s","read_timeout":6,"read_timeout_unit":"s","retries":1,"layer_policy":null,"balancer2":null}' \
    --condition '{"variable":{"name":"uri"},"operator":{"name":"eq"},"values":[{"type":"str","val":"/a/b"}]}'

  1. proxy a global k8s upstream
> oredge create page-rule 1 --proxy '{"upstream":[{"global_k8s_cluster":1836,"weight":1}],"backup_upstream":[],"upstream_el_code":"","balancer":{"algorithm":"roundrobin","variables":[]},"useSameBalancingPolicy":true,"sticky":{"enable":false,"key":"Edge-Sticky","level":"upstream","ttl":0,"mode":"none"},"retry_condition":["error","timeout","invalid_header","http_500","http_502","http_504"],"connect_timeout":6,"connect_timeout_unit":"s","send_timeout":6,"send_timeout_unit":"s","read_timeout":6,"read_timeout_unit":"s","retries":1,"layer_policy":null,"balancer2":null}' \
    --condition '{"variable":{"name":"uri"},"operator":{"name":"eq"},"values":[{"type":"str","val":"/a/b"}]}'