I don't understand proxy-rewrite - regex_uri #6490
Replies: 3 comments 4 replies
-
How did you verify that the request was forwarded to 2.2.2.2? Basically this is not possible. |
Beta Was this translation helpful? Give feedback.
-
version
Sorry for being late. There's something wrong with what I said before step
At this time, if you visit apisix:9080/code2, you will jump to 8080/aaa |
Beta Was this translation helpful? Give feedback.
-
my recurrence steps:
http {
server {
listen 8081;
access_log off;
location / {
return 200 "8081";
}
}
server {
listen 8082;
access_log off;
location / {
return 200 "8082";
}
}
}
curl --location --request PUT 'http://127.0.0.1:9080/apisix/admin/routes/1' \
--header 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' \
--header 'Content-Type: application/json' \
--data-raw '{
"uri": "/code*",
"name": "code1",
"methods": [
"GET",
"POST",
"PUT",
"DELETE",
"PATCH",
"HEAD",
"OPTIONS",
"CONNECT",
"TRACE"
],
"upstream": {
"nodes": [
{
"host": "127.0.0.1",
"port": 8081,
"weight": 1
}
],
"timeout": {
"connect": 6,
"send": 6,
"read": 6
},
"type": "roundrobin",
"scheme": "http",
"pass_host": "pass",
"keepalive_pool": {
"idle_timeout": 60,
"requests": 1000,
"size": 320
}
},
"status": 1
}'
curl --location --request PUT 'http://127.0.0.1:9080/apisix/admin/routes/2' \
--header 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' \
--header 'Content-Type: application/json' \
--data-raw '{
"uri": "/code2*",
"name": "code2",
"methods": [
"GET",
"POST",
"PUT",
"DELETE",
"PATCH",
"HEAD",
"OPTIONS",
"CONNECT",
"TRACE"
],
"plugins": {
"proxy-rewrite": {
"uri": "/aaa"
}
},
"upstream": {
"nodes": [
{
"host": "127.0.0.1",
"port": 8082,
"weight": 1
}
],
"timeout": {
"connect": 6,
"send": 6,
"read": 6
},
"type": "roundrobin",
"scheme": "http",
"pass_host": "pass",
"keepalive_pool": {
"idle_timeout": 60,
"requests": 1000,
"size": 320
}
},
"status": 1
}'
$ curl http://127.0.0.1:9080/code2
8082 The request is captured by route 2 and sent upstream to port 8082. I can't reproduce the problem that I said to you. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
我有两个Route
第一个直接请求code,然后不动转发到后端 1.1.1.1:8080/code。用的域名是aaa.com.cn
第二个是请求code2,然后会正则变成code,请求后端的2.2.2.2:8080/code,域名也是aaa.com.cn
这个时候,请求code2的时候,apisix会把请求变成code后,请求第一个route,变成请求1.1.1.1:8080;而不是请求route2的上游。如果没有第一个请求,就完全没问题,请求2.2.2.2:8080。
按道理apisix如果认为正则转发后的是一个route时,没有第一个route不应该报错404吗?
En:
I have two routes
The first one directly requests code, and then forwards it to the backend 1.1.1.1:8080 / code. The domain name used is AAA com. cn
The second is to request code2, and then it will be regularized into code. The back-end of the request is 2.2.2.2:8080 / code, and the domain name is AAA com. cn
At this time, when requesting code2, apisik will change the request into code and request the first route into request 1.1.1.1:8080; Instead of requesting the upstream of route2. If there is no first request, there is no problem at all. Request 2.2.2.2:8080.
According to the truth, if apisik thinks that the route after regular forwarding is a route, shouldn't it report Error 404 without the first route?
Route 1
{
"uri": "/code*",
"name": "code",
"host": "aaa.com.cn",
"upstream": {
"nodes": [
{
"host": "1.1.1.1",
"port": 8080,
"weight": 1
}
],
"type": "roundrobin",
"scheme": "http",
"pass_host": "pass",
"keepalive_pool": {
"idle_timeout": 60,
"requests": 1000,
"size": 320
}
},
"status": 1
}
Route 2
{
"uri": "/code2*",
"name": "code2",
"host": "aaa.com.cn",
"plugins": {
"proxy-rewrite": {
"regex_uri": [
"^/code2(.*)",
"/code$1"
]
}
},
"upstream": {
"nodes": [
{
"host": "2.2.2.2",
"port": 8080,
"weight": 1
}
],
"timeout": {
"connect": 6,
"send": 6,
"read": 6
},
"type": "roundrobin",
"scheme": "http",
"pass_host": "pass",
"keepalive_pool": {
"idle_timeout": 60,
"requests": 1000,
"size": 320
}
},
"status": 1
}
Beta Was this translation helpful? Give feedback.
All reactions