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
On Sat, Oct 14, 2017 at 11:06 AM, Recolic Keghart
<recoli...@gmail.com> wrote:
> 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?.