Reputation: 4012
I want to create a Location in my Nginx with such route /resource/{{state}} though the {{state}} is a place holder for a variable that must pass to my Lua script and according to this variable I want to process some resources.
I cannot find any documentation or guideline for creating such a route in Nginx and passing path parameters to Lua. Are path parameters available in nginx and if the answer is yes how can I access them in mylua code?
Upvotes: 1
Views: 1025
Reputation: 1535
Use the regex location syntax with the ngx.var.VARIABLE API:
location ~ ^/resource/(?<state>[^/]+)/?$ {
content_by_lua_block {
ngx.say(ngx.var.state)
}
}
Note: nginx uses the PCRE2 library for regex support. Check the documentation for the syntax.
Upvotes: 2