Is it possible with Lua to set an NGINX variable within a location block to a value read from a file?
I'm working with an NGINX container, deployed within a kubernetes pod. I have a value that is set in a file rather than an environment variable
e.g.
set $a_key <a_value_from_file_set_here>; I have attempted to do something similar to this:
set_by_lua_block $a_key { file = io.open('/tmp/string.txt', 'r') local data = file:read() io.close(file) return data } The above caused a 500 error and was based on the example here https://onelinerhub.com/nginx-lua/how-to-read-file-with-lua
I haven't been able to get this working so far. I'm wondering if it's even possible or desirable. I know I can configure NGINX if I set the value as an environment variable using envsubst. My reason for looking into achieving the same with Lua is because this will avoid having to override the docker entrypoint with shell commands which has some advantages in terms of decluttering the Kubernetes code