Get full url using nginx and lua with openresty

If the request URL

test.com/gifts.
If i use
 ngx.var.uri
, output
/ gifts /
expected output
test.com/gifts
Code:
 location / gifts {
                    try_files $ uri @url_change;
                }


                location @url_change {
                default_type text / html;
                content_by_lua '

                        ngx.say (ngx.var.uri)
                         ';
                }
+4
source share
4 answers

I really don't understand what you want, but if you want the actual full url, I think you can use this

$http_host$request_uri;
+13
source
ngx.say(ngx.var.host .. '/' .. ngx.var.uri)
+3
source

$host, .. ngx.var.host?

+2

- uri, :

ngx.var.request_uri

So far ngx.var.uri, the new uri after rewriting ngx.

Try:

ngx.say(ngx.var.request_uri)

+1
source

All Articles