I am trying to set up a custom response when upstream triggers a 404 or any 4xx/5xx codes(cant do it on upstream itself, I can control only the proxy layer)
Following is my code snippet
package.path = package.path .. ";/home/usr/test/readme.lua"
content = require('readme')
if ngx.status == ngx.HTTP_SERVICE_UNAVAILABLE or ngx.status == ngx.HTTP_INTERNAL_SERVER_ERROR then
local chunk, eof = ngx.arg[1], ngx.arg[2]
if not eof then
ngx.arg[1] = nil
else
ngx.arg[1] = content
end
end
My readme.lua file
local f = io.open("errorpage.html", "r")
local content = f:read("*all")
f:close()
return content
errorpage.html
<html>
<head></head>
<title>Test Error Page</title>
<body> Testing custom error page</body>
</html>
When I try running this I get "ERR CONTENT DECODING FAILED" in browser.
Thank you in advance for any help.