apache / apisix

The Cloud-Native API Gateway
https://apisix.apache.org/blog/
Apache License 2.0
14.54k stars 2.52k forks source link

help request: matching rules and priority #11437

Open GitHubLoveKe opened 4 months ago

GitHubLoveKe commented 4 months ago

Description

我配置了通配域名.test.com匹配路由/xxxxx/ 在3.2.2的版本可以正常匹配到 但是升级后通配域名匹配不到,目前已测试3.9.1,3.8.1 因为/xxxxx/*是一个公共的东西,所以所有的都可以访问

Environment

i used apisix v3.8.1 ,v3.9.1

zhoujiexiong commented 3 months ago

@GitHubLoveKe

I tested with APISIX v3.9.0, it's OK, would you pls. confirm again?

use t::APISIX 'no_plan';

repeat_each(1);
no_long_string();
no_shuffle();
no_root_location();
run_tests;

__DATA__

=== TEST 1: try reproduce issue #11437
--- config
    location = /t {
        content_by_lua_block {
            local t = require("lib.test_admin").test
            local code, body = t('/apisix/admin/routes/11437',
                ngx.HTTP_PUT,
                [[{
                    "plugins": {
                        "serverless-pre-function": {
                            "phase": "rewrite",
                            "functions": [
                                "return function (conf, ctx) ngx.print(\"11437\"); ngx.exit(200) end"
                            ]
                        }
                    },
                    "hosts": ["*.test.com"],
                    "uri": "/xxx/*"
                }]]
            )
            assert(body == "passed")

            ngx.sleep(3)

            local http = require "resty.http"
            local httpc = http.new()
            local uri1 = "http://127.0.0.1:" .. ngx.var.server_port .. "/xxx/foo"
            local res, err = httpc:request_uri(uri1, { method = "GET", headers = { Host = "foo.test.com" }})
            if err then
                ngx.log(ngx.ERR, err)
                ngx.status = res.status
                return
            end
            ngx.say(res.body)
        }
    }
--- request
GET /t
--- response_body
11437
--- timeout: 30
GitHubLoveKe commented 3 months ago

I have both .test.com/xxx/ and foo.test.com/ routes if no have foo.test.com/ , i can access foo .test.com/xxx/* I adjusted the priority value , not work

but i can use it on v3.2.2

{ "uri": "/xxx/", "name": "xxx", "priority": 100, "methods": [ "GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS", "CONNECT", "TRACE", "PURGE" ], "host": ".test.com", "upstream": { "nodes": [ { "host": "192.168.88.11", "port": 19000, "weight": 1 } ], "timeout": { "connect": 6, "send": 600, "read": 600 }, "type": "roundrobin", "hash_on": "vars", "scheme": "http", "pass_host": "pass", "keepalive_pool": { "idle_timeout": 60, "requests": 1000, "size": 320 } }, "enable_websocket": true, "status": 1 }

like this image

zhoujiexiong commented 3 months ago

I have both .test.com/xxx/ and foo.test.com/ routes if no have foo.test.com/ , i can access foo .test.com/xxx/* I adjusted the priority value , not work

but i can use it on v3.2.2

{ "uri": "/xxx/", "name": "xxx", "priority": 100, "methods": [ "GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS", "CONNECT", "TRACE", "PURGE" ], "host": ".test.com", "upstream": { "nodes": [ { "host": "192.168.88.11", "port": 19000, "weight": 1 } ], "timeout": { "connect": 6, "send": 600, "read": 600 }, "type": "roundrobin", "hash_on": "vars", "scheme": "http", "pass_host": "pass", "keepalive_pool": { "idle_timeout": 60, "requests": 1000, "size": 320 } }, "enable_websocket": true, "status": 1 }

like this image

@GitHubLoveKe

Simulated the case you just provided, It's also no problem. :D

foo.test.com/xxx/foo is reachable via new added route 11437_foo.

image
use t::APISIX 'no_plan';

repeat_each(1);
no_long_string();
no_shuffle();
no_root_location();
run_tests;

__DATA__

=== TEST 1: try reproduce issue #11437
--- config
    location = /t {
        content_by_lua_block {
            local t = require("lib.test_admin").test
            local code, body = t('/apisix/admin/routes/11437',
                ngx.HTTP_PUT,
                [[{
                    "plugins": {
                        "serverless-pre-function": {
                            "phase": "rewrite",
                            "functions": [
                                "return function (conf, ctx) ngx.print(\"11437\"); ngx.exit(200) end"
                            ]
                        }
                    },
                    "hosts": ["*.test.com"],
                    "uri": "/xxx/*"
                }]]
            )
            assert(body == "passed")

            local code, body = t('/apisix/admin/routes/11437_foo',
                ngx.HTTP_PUT,
                [[{
                    "plugins": {
                        "serverless-pre-function": {
                            "phase": "rewrite",
                            "functions": [
                                "return function (conf, ctx) ngx.print(\"11437_foo\"); ngx.exit(200) end"
                            ]
                        }
                    },
                    "hosts": ["foo.test.com"],
                    "uri": "/*"
                }]]
            )
            assert(body == "passed")

            ngx.sleep(3)

            local http = require "resty.http"
            local httpc = http.new()
            local uri1 = "http://127.0.0.1:" .. ngx.var.server_port .. "/xxx/foo"
            local res, err = httpc:request_uri(uri1, { method = "GET", headers = { Host = "foo.test.com" }})
            if err then
                ngx.log(ngx.ERR, err)
                ngx.status = res.status
                return
            end
            ngx.say(res.body)
        }
    }
--- request
GET /t
--- response_body
11437_foo
--- timeout: 30
zhoujiexiong commented 3 months ago

Hi @GitHubLoveKe

Have you solved your problem?