添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

ccxhwmy
Anything can be modified,include uri parameter head body
ngx.req.set_method(method_id) method_id=ngx.HTTP_POST ngx.HTTP_GET
ngx.req.set_uri(uri, jump?)
ngx.req.set_uri_args("a=3&b=hello%20world") == ngx.var.args="a=3&b=hello%20world"
ngx.req.set_body_data("a=1&b=2")

also, you can use some nginx directive to sth
proxy_set_header field value;
proxy_set_body value;

Mickle
Thank you for your answer, But I found that neither ngx.req.set_uri nor ngx.req.set_uri_args can modify the ngx.var.request_uri .
The ngx.req.set_uri(uri, true) can jump to a new location, but the ngx.var.request_uri is old in the new location. It can only mofidy the uri which to upstream. Is there some way to modify the value of ngx.var.request_uri ?

ccxhwmy
ngx.req.set_uri_args(args)
ngx.req.set_uri(uri,jump) --uri only ,Do not contain parameter
The optional boolean jump argument can trigger location rematch (or location jump) as ngx_http_rewrite_module's rewrite directive, that is, when jump is true (default to false), this function will never return and it will tell Nginx to try re-searching locations with the new URI value at the later post-rewrite phase and jumping to the new location.

if you want to give off all parameter,use follow method
ngx.var.args=nil

garoll
Our project fetch the value of ngx.var.request_uri in many place to do something, but we want to modify the value of ngx.var.request_uri in the begin of a request recently.
So we want to find out a way to modify it.
Maybe openresty does not support this way.

        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

Mickle Hi~
Unfortunately no response from server, there is no server 127.0.0.1:8888 in fact.
Because I just want to display the error.log.

ccxhwmy
Use a nginx varible replice $request_uri in log format,for example $myrequest_uri ,declear it in nginx configure file
set $myrequest_uri $request_uri;
local tmp=ngx.var.uri
if ngx.var.args then tmp=tmp.."?"..args end
ngx.var.myrequest_uri=tmp