nginxluaresty

Ignore content_by_lua_file under some circumstances and let NGINX do it's job


In my NGINX-config I have

location /x {
  access_by_lua_file auth/auth.lua;
  content_by_lua_file auth/content.lua;
}

access_by_lua_file works fine. I i return nothing there it continues to content_by_lua_file. I want it to replace the content under certain circumstances and otherwise continue and serve the static file as if the content_by_lua_file-directive would not have existed.

content.lua looks like this:

local files_cache = require 'files_cache'

local filePath = ngx.var.file_path
local fileContent = files_cache.load(filePath)

if fileContent ~= nil then
  ngx.header["X-Source"] = "Cache"
  ngx.say(fileContent)
  ngx.status = ngx.HTTP_OK
  return ngx.exit(ngx.status)
end

Solution

  • I found a solution:

    I have to put ngx.exec(ngx.var.file_path) in the end to return the ball to NGINX.