request no_lua current page?

24 views
Skip to first unread message

Recolic Keghart

unread,
Oct 14, 2017, 2:06:48 PM10/14/17
to openresty-en
I'm trying to show HEADER.html before response and FOOTER.html after response. (Example: https://mirrors.aliyun.com/ubuntu-releases/17.10/) So I wrote this script:

```
http {
    server {
        listen 8080;
        root /var/www/html;
        index index.html;
        autoindex on;
        location ~ 1/$ {
                default_type text/html;
                content_by_lua_block {
-- ------------------------------------------------------
function file_exists(name)
   local f=io.open(name,"r")
   if f~=nil then io.close(f) return true else return false end
end

function readAll(file)
    local f = io.open(file, "rb")
    local content = f:read("*all")
    f:close()
    return content
end

function try_say(fname)
   if file_exists(fname) then
      ngx.say(readAll(fname))
   end
end

local pref = ngx.var.document_root .. ngx.var.uri
try_say(pref .. "HEADER.html")
-- local res = ngx.location.capture(ngx.var.uri .. '?nolua=1')
-- ??????? ngx.say(show_current_page_without_lua()) ???????
try_say(pref .. "FOOTER.html")
-- --------------------------------------------------------
                }
        }
    }
}
```

I'm stuck to show origin page... Are there any possible way to implement it?

Yichun Zhang (agentzh)

unread,
Oct 16, 2017, 3:13:48 PM10/16/17
to openresty-en
Hello!

You cannot mix content_by_lua* and the static file module in the same
location. For each nginx location, only one nginx module can control
how to generate the response. Maybe you should check out the
body_filter_by_lua* and header_filter_by_lua* directives instead? You
need a body filter in this case. BTW, the subrequest API
ngx.location.capture* require full buffering, better avoid it.

Regards,
Yichun
> --
> You received this message because you are subscribed to the Google Groups
> "openresty-en" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to openresty-en...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages