1

I have this location block:

location /somewhere/ {
    access_by_lua_file /path/to/file.lua;
    add_header X-debug-message "Using location: /somewhere/" always;
    ...
}

and I would like to do two things:

  1. I would like to move the header setting line into the lua file.
  2. For that I have to read the location definition (matching string/regex/...) from a variable rather than typing it in as a static string ("/somewhere/").

So in the end it should just look like this with magic in the lua file (I know how to set a response header in lua).

location /somewhere/ {
    access_by_lua_file /path/to/file.lua;
    ...
}

My problem: I have no clue...

  1. ...if there is a variable storing the location desciption ("/somewhere/") - and not the requested URI/URL/PATH and
  2. if so - where that variable can be found.

So how do I access this information from within lua code?

Example

Called URL: https://mydomain.nowhere/somewhere/servicex/1234

Location that matches: "location /somewhere/ { ..."

String I want to get: "/somewhere/" (so exactly the definition of the location block).

eventhorizon
  • 2,977
  • 8
  • 33
  • 57
  • Maybe this would help you: https://stackoverflow.com/questions/20000911/get-complete-url-using-nginx-and-lua-with-openresty/46326942 and https://stackoverflow.com/questions/48708361/nginx-request-uri-vs-uri/48709976 – un.def May 18 '21 at 08:23
  • If I use this/these variables I do not get the string I defined the location with but the real URI/URI/PATH/REWRITTEN-PATH/... But THX ;-) – eventhorizon May 18 '21 at 08:57
  • Did you ever find an answer to this? I have the same problem – Marius Kimmina Aug 05 '21 at 15:24
  • No. I modified the lua path and just added my location. – eventhorizon Aug 06 '21 at 06:18

0 Answers0