apisix icon indicating copy to clipboard operation
apisix copied to clipboard

request help: plugin proxy-rewrite in service not work

Open cverdela opened this issue 5 years ago • 8 comments

Issue description

service: { "update_time": 1618987372, "id": "348075546078347976", "upstream_id": "351386306183430857", "plugins": { "proxy-rewrite": { "headers": { "Authorization": "Basic Y2p0ZXN0OjEyMw==" } }, "serverless-pre-function": { "disable": false, "phase": "rewrite", "functions": [ "return function() ngx.log(ngx.WARN,'----rewrite--rewrite---') end" ] } }, "desc": "测试", "name": "test", "create_time": 1616998792 }

serverless-pre-function logged

Environment

  • apisix version (cmd: apisix version):2.3
  • etcd version, if have (cmd: run curl http://127.0.0.1:9090/v1/server_info to get the info from server-info API):3.4.9
  • apisix-dashboard version, if have:2.4

cverdela avatar Apr 21 '21 07:04 cverdela

According to the information provided, it cannot be seen that the proxy-rewrite plugin does not take effect. Can your upstream receive the request header of "Authorization": "Basic Y2p0ZXN0OjEyMw=="?

Firstsawyou avatar Apr 21 '21 07:04 Firstsawyou

can't

cverdela avatar Apr 21 '21 08:04 cverdela

the upstream is another route with plugin that

"serverless-pre-function": {
                    "phase": "rewrite",
                    "functions": [
                        "return function() ngx.req.read_body()  local ri=ngx.var.request_uri local body=ngx.req.get_body_data() local headers_tab = ngx.req.get_headers() for k,v in pairs(headers_tab) do ngx.log(ngx.ERR,'--header--'..k..':'..v..'--header--') end if nil ~= body then ngx.log(ngx.ERR,'----uri-----'..ri..'----uri-----') ngx.log(ngx.ERR,'----body-----'..body..'----body-----') end end"
                    ]
                },

and logs were

2021/04/21 07:29:28 [warn] 43#43: *138489 [lua] plugin.lua:331: trace_plugins_info_for_debug(): Apisix-Plugins: , client: 172.28.0.1, server: , request: "GET /web1.txt HTTP/1.1", host: "127.0.0.1:9080"
2021/04/21 07:29:28 [warn] 43#43: *138489 [lua] plugin.lua:331: trace_plugins_info_for_debug(): Apisix-Plugins: , client: 172.28.0.1, server: , request: "GET /web1.txt HTTP/1.1", host: "127.0.0.1:9080"
2021/04/21 07:29:28 [warn] 43#43: *138489 [lua] plugin.lua:331: trace_plugins_info_for_debug(): Apisix-Plugins:  while logging request, client: 172.28.0.1, server: , request: "GET /web1.txt HTTP/1.1", host: "127.0.0.1:9080"
2021/04/21 07:29:28 [warn] 43#43: *138486 [lua] plugin.lua:331: trace_plugins_info_for_debug(): Apisix-Plugins:  while sending to client, client: 172.28.0.1, server: , request: "GET /we/web1.txt HTTP/1.1", upstream: "http://127.0.0.1:9080/web1.txt", host: "127.0.0.1:9080"
2021/04/21 07:29:28 [warn] 43#43: *138486 [lua] plugin.lua:331: trace_plugins_info_for_debug(): Apisix-Plugins:  while sending to client, client: 172.28.0.1, server: , request: "GET /we/web1.txt HTTP/1.1", upstream: "http://127.0.0.1:9080/web1.txt", host: "127.0.0.1:9080"
2021/04/21 07:29:28 [warn] 43#43: *138486 [lua] plugin.lua:331: trace_plugins_info_for_debug(): Apisix-Plugins:  while logging request, client: 172.28.0.1, server: , request: "GET /we/web1.txt HTTP/1.1", upstream: "http://127.0.0.1:9080/web1.txt", host: "127.0.0.1:9080"
2021/04/21 07:29:29 [warn] 43#43: *138486 [lua] [string "return function() ngx.log(ngx.WARN,'----rewri..."]:1: func(): ----rewrite--rewrite---, client: 172.28.0.1, server: , request: "GET /we/web1.txt HTTP/1.1", host: "127.0.0.1:9080"
2021/04/21 07:29:29 [error] 43#43: *138489 [lua] [string "return function() ngx.req.read_body()  local ..."]:1: func(): --header--x-real-ip:172.28.0.1--header--, client: 172.28.0.1, server: , request: "GET /web1.txt HTTP/1.1", host: "127.0.0.1:9080"
2021/04/21 07:29:29 [error] 43#43: *138489 [lua] [string "return function() ngx.req.read_body()  local ..."]:1: func(): --header--x-forwarded-for:172.28.0.1--header--, client: 172.28.0.1, server: , request: "GET /web1.txt HTTP/1.1", host: "127.0.0.1:9080"
2021/04/21 07:29:29 [error] 43#43: *138489 [lua] [string "return function() ngx.req.read_body()  local ..."]:1: func(): --header--x-forwarded-proto:http--header--, client: 172.28.0.1, server: , request: "GET /web1.txt HTTP/1.1", host: "127.0.0.1:9080"
2021/04/21 07:29:29 [error] 43#43: *138489 [lua] [string "return function() ngx.req.read_body()  local ..."]:1: func(): --header--x-forwarded-host:127.0.0.1--header--, client: 172.28.0.1, server: , request: "GET /web1.txt HTTP/1.1", host: "127.0.0.1:9080"
2021/04/21 07:29:29 [error] 43#43: *138489 [lua] [string "return function() ngx.req.read_body()  local ..."]:1: func(): --header--x-forwarded-port:9080--header--, client: 172.28.0.1, server: , request: "GET /web1.txt HTTP/1.1", host: "127.0.0.1:9080"
2021/04/21 07:29:29 [error] 43#43: *138489 [lua] [string "return function() ngx.req.read_body()  local ..."]:1: func(): --header--cache-control:no-cache--header--, client: 172.28.0.1, server: , request: "GET /web1.txt HTTP/1.1", host: "127.0.0.1:9080"
2021/04/21 07:29:29 [error] 43#43: *138489 [lua] [string "return function() ngx.req.read_body()  local ..."]:1: func(): --header--postman-token:89037d99-dc2f-4cf0-8294-ec707a9b5bbc--header--, client: 172.28.0.1, server: , request: "GET /web1.txt HTTP/1.1", host: "127.0.0.1:9080"
2021/04/21 07:29:29 [error] 43#43: *138489 [lua] [string "return function() ngx.req.read_body()  local ..."]:1: func(): --header--host:127.0.0.1:9080--header--, client: 172.28.0.1, server: , request: "GET /web1.txt HTTP/1.1", host: "127.0.0.1:9080"
2021/04/21 07:29:29 [error] 43#43: *138489 [lua] [string "return function() ngx.req.read_body()  local ..."]:1: func(): --header--accept:*/*--header--, client: 172.28.0.1, server: , request: "GET /web1.txt HTTP/1.1", host: "127.0.0.1:9080"
2021/04/21 07:29:29 [error] 43#43: *138489 [lua] [string "return function() ngx.req.read_body()  local ..."]:1: func(): --header--accept-encoding:gzip, deflate--header--, client: 172.28.0.1, server: , request: "GET /web1.txt HTTP/1.1", host: "127.0.0.1:9080"
2021/04/21 07:29:29 [error] 43#43: *138489 [lua] [string "return function() ngx.req.read_body()  local ..."]:1: func(): --header--user-agent:PostmanRuntime/6.4.1--header--, client: 172.28.0.1, server: , request: "GET /web1.txt HTTP/1.1", host: "127.0.0.1:9080"

and access log were

172.28.0.1 - - [21/Apr/2021:07:29:29 +0000] 127.0.0.1:9080 "GET /web1.txt HTTP/1.1" 401 58 0.000 "-" "PostmanRuntime/6.4.1" - - - "http://127.0.0.1:9080"
172.28.0.1 - - [21/Apr/2021:07:29:29 +0000] 127.0.0.1:9080 "GET /we/web1.txt HTTP/1.1" 401 58 0.002 "-" "PostmanRuntime/6.4.1" 127.0.0.1:9080 401 0.000 "http://127.0.0.1:9080"

cverdela avatar Apr 21 '21 08:04 cverdela

@Firstsawyou

cverdela avatar Apr 21 '21 08:04 cverdela

server: , request: "GET /we/web1.txt HTTP/1.1", host: "127.0.0.1:9080" server: , request: "GET /web1.txt HTTP/1.1", host: "127.0.0.1:9080"

These two routes are not related and cannot be used as upstream to receive request data. You can configure a real upstream service to receive proxy-rewrite plugin request data and print it out.

Firstsawyou avatar Apr 21 '21 08:04 Firstsawyou

If there is any problem, you should trust me and repeat it

cverdela avatar Apr 21 '21 09:04 cverdela

https://github.com/apache/apisix/issues/4104 bug

cverdela avatar Apr 22 '21 01:04 cverdela

surpassed by #4104

spacewander avatar Apr 22 '21 02:04 spacewander