I config the nginx.conf
like:
location /request_aaa {
rewrite_by_lua_block {
ngx.log(ngx.ERR, "request_uri in location request_aaa: ", ngx.var.request_uri)
ngx.req.set_uri("/request_bbb", true)
}
}
location /request_bbb {
rewrite_by_lua_block {
ngx.log(ngx.ERR, "request_uri in location request_bbb: ", ngx.var.request_uri)
ngx.log(ngx.ERR, "uri in location request_bbb: ", ngx.var.uri)
}
proxy_pass http://127.0.0.1:8888;
}
I make a request like:
curl "http://127.0.0.1/request_aaa"
The error.log is:
2022/08/05 22:47:26 [error] 18673#0: *25 [lua] rewrite_by_lua(nginx.conf:64):2: request_uri in location request_aaa: /request_aaa, client: 192.168.18.128, server: localhost, request: "GET /request_aaa HTTP/1.1", host: "192.168.18.128"
2022/08/05 22:47:26 [error] 18673#0: *25 [lua] rewrite_by_lua(nginx.conf:71):2: request_uri in location request_bbb: /request_aaa, client: 192.168.18.128, server: localhost, request: "GET /request_aaa HTTP/1.1", host: "192.168.18.128"
2022/08/05 22:47:26 [error] 18673#0: *25 [lua] rewrite_by_lua(nginx.conf:71):3: uri in location request_bbb: /request_bbb, client: 192.168.18.128, server: localhost, request: "GET /request_aaa HTTP/1.1", host: "192.168.18.128"
We can find that ngx.var.request_uri
does not change in the location /request_bbb