If request URL is
test.com/gifts.If i am using
ngx.var.urioutput is
/gifts/expected output is
test.com/giftsCode :
location /gifts { try_files $uri @url_change; } location @url_change { default_type text/html; content_by_lua ' ngx.say(ngx.var.uri) '; }
Nginx+Lua is a self-contained web server embedding the scripting language Lua. Powerful applications can be written directly inside Nginx without using cgi, fastcgi, or uwsgi. By adding a little Lua code to an existing Nginx configuration file, it is easy to add small features.
LuaJIT 2.0. x is always supported in OpenResty though LuaJIT 2.1+ is highly recommended.
OpenResty® is a full-fledged web platform that integrates our enhanced version of the Nginx core, our enhanced version of LuaJIT, many carefully written Lua libraries, lots of high quality 3rd-party Nginx modules, and most of their external dependencies.
I don't really understand what you want, but if you want the actual full URL i think you can use this
$http_host$request_uri;
If anyone is looking for the original request uri, it's here:
ngx.var.request_uri
While ngx.var.uri
is the new uri after ngx rewrite phase.
Try it:
ngx.say(ngx.var.request_uri)
ngx.say(ngx.var.host .. '/' .. ngx.var.uri)
Isn't what you need just the $host
variable, i.e. ngx.var.host
?
Generate the full url and avoid getting an error when query_string is nil:
local full_url = ngx.var.scheme.."://"..ngx.var.http_host..ngx.var.request_uri
if ngx.var.query_string ~= nil then
full_url = full_url.."?"..ngx.var.query_string
end
ngx.say(full_url)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With