这些是我的kong apis:
{
"total" : 5,
"data" : [
{
"upstream_read_timeout" : 60000,
"retries" : 5,
"strip_uri" : false,
"upstream_connect_timeout" : 60000,
"created_at" : 1515179488893,
"preserve_host" : false,
"https_only" : false,
"upstream_send_timeout" : 60000,
"uris" : [
"/users/\\d"
],
"id" : "edbc93f2-e897-490f-a0a5-7fb627eb8748",
"upstream_url" : "http://172.18.0.3:8002",
"http_if_terminated" : false,
"name" : "account"
},
{
"upstream_send_timeout" : 60000,
"id" : "2d76ec3e-df4d-43f1-8bbb-79e613f882a8",
"uris" : [
"/\\w"
],
"upstream_url" : "http://172.18.0.3:8002",
"http_if_terminated" : false,
"name" : "login",
"upstream_read_timeout" : 60000,
"strip_uri" : false,
"retries" : 5,
"upstream_connect_timeout" : 60000,
"created_at" : 1515179488936,
"https_only" : false,
"preserve_host" : false
},
{
"name" : "event",
"upstream_url" : "http://172.18.0.10:8004",
"http_if_terminated" : false,
"uris" : [
"/users/\\d /calendars/\\d /events"
],
"id" : "2f5c90de-dc09-43f3-92d4-7d798b6fd149",
"upstream_send_timeout" : 60000,
"preserve_host" : false,
"https_only" : false,
"retries" : 5,
"strip_uri" : false,
"upstream_connect_timeout" : 60000,
"created_at" : 1515179488801,
"upstream_read_timeout" : 60000
},
{
"preserve_host" : false,
"https_only" : false,
"created_at" : 1515179488610,
"retries" : 5,
"strip_uri" : false,
"upstream_connect_timeout" : 60000,
"upstream_read_timeout" : 60000,
"name" : "instructions",
"http_if_terminated" : false,
"upstream_url" : "http://172.18.0.13:8005",
"uris" : [
"/users/\\d /calendars/\\d /events/\\d /recurrence/\\d /instruction"
],
"id" : "4e0462ff-3446-4f2a-9a54-d0e6fb385a2c",
"upstream_send_timeout" : 60000
},
{
"retries" : 5,
"upstream_connect_timeout" : 60000,
"strip_uri" : false,
"created_at" : 1515179488849,
"preserve_host" : false,
"https_only" : false,
"upstream_read_timeout" : 60000,
"upstream_url" : "http://172.18.0.7:8003",
"http_if_terminated" : false,
"name" : "calendar",
"upstream_send_timeout" : 60000,
"uris" : [
"/users/\\d /calendars"
],
"id" : "1e12ba7e-571b-4d02-9e70-a6823db0606d"
}
]
}
使用以下命令创建:
# instructions
curl -i -X POST http://localhost:8001/apis/ \
-d 'name=instructions' \
-d 'upstream_url=http://172.18.0.13:8005' \
-d 'uris=/users/\d+/calendars/\d+/events/\d+/recurrence/\d+/instruction' \
-d 'strip_uri=false'
curl -i -X POST http://localhost:8001/apis/instructions/plugins --data "name=jwt"
# event
curl -i -X POST http://localhost:8001/apis/ \
-d 'name=event' \
-d 'upstream_url=http://172.18.0.10:8004' \
-d 'uris=/users/\d+/calendars/\d+/events' \
-d 'strip_uri=false'
curl -i -X POST http://localhost:8001/apis/event/plugins --data "name=jwt"
# calendar
curl -i -X POST http://localhost:8001/apis/ \
-d 'name=calendar' \
-d 'upstream_url=http://172.18.0.7:8003' \
-d 'uris=/users/\d+/calendars' \
-d 'strip_uri=false'
curl -i -X POST http://localhost:8001/apis/calendar/plugins --data "name=jwt"
# account
curl -i -X POST http://localhost:8001/apis/ \
-d 'name=account' \
-d 'upstream_url=http://172.18.0.3:8002' \
-d 'uris=/users/\d+' \
-d 'strip_uri=false'
curl -i -X POST http://localhost:8001/apis/account/plugins --data "name=jwt"
# login
curl -i -X POST http://localhost:8001/apis/ \
-d 'name=login' \
-d 'upstream_url=http://172.18.0.3:8002' \
-d 'uris=/\w/' \
-d 'strip_uri=false'
如果我尝试访问/users/3/calendars
,我会被重定向到account
api(使用uris=/users/\d+
定义),但我希望将其重定向到{ {1}} api(用calendar
定义)。来自docs:
如前所述,Kong按长度评估前缀URI:首先评估最长前缀URI。但是, Kong将根据定义的顺序评估正则表达式URI。
我做错了什么? 谢谢你的时间。
答案 0 :(得分:1)
问题出在curl
命令中,以便在设置uris +
时需要使用--data-urlencode
代替-d