lua-nginx-module icon indicating copy to clipboard operation
lua-nginx-module copied to clipboard

ngx.exit and custom body

Open leavesbnw opened this issue 9 years ago • 2 comments

Hi I am using the latest offical openresty. I'm building a redis+lua+openresty environment,which the configuration is:

server {
 ...
error_page  404   /404.html;  
location / {         
       content_by_lua_block {
                local redis = require "resty.redis"
                local red = redis:new()
                local ok,err = red:connect("127.0.01",6379)
                if not ok then
                        ngx.say("failed to connect: ",err)
                        return
                end
                local res,err = red:hget("mykey","mytestfield")
                if not res then
                        ngx.say("failed to get data: ",err)
                        return
                end
                if res == ngx.null then
                        ngx.status = 404
                        return ngx.exit(ngx.HTTP_NOT_FOUND)
                end
                ngx.say(res)
          }
     }
}

when found no data in redis,it return ngx.exit(ngx.HTTP_NOF_FOUND).I want it to return handler to nginx to process status 404 using error_page directive.How can I do that?

leavesbnw avatar Dec 19 '16 06:12 leavesbnw

error_page as well as content_by_lua_block are content handlers. You might wanna change to access_by_lua_block. Nevertheless such questions usually belong to the mailing list: https://groups.google.com/forum/#!forum/openresty-en

bjoe2k4 avatar Dec 19 '16 07:12 bjoe2k4

Is this issue resolve .I tried both content and access by lua block to return ngx.exit(503) which is having error_page directive. But browser is still showing default 503 page.

rest17 avatar May 01 '20 23:05 rest17