In an Nginx+Lua environment, how to replace part of the response data before returning it?
阿神
阿神 2017-05-16 17:12:34
0
3
771

As the title...Build an environment for the nginx+lua-nginx-module module

Access the URL /abc and return the data of a.html

But before returning data
you need to replace <p>111</p> in a.html with <p>222< /p>

Can I do this with Lua?

The current attempt is to try to get the return data in body_filter_by_lua_filengx.arg[1]
But I can’t get it...Where should the return data be? What about acquisition and processing?

阿神
阿神

闭关修行中......

reply all(3)
滿天的星座

It can certainly be done. This is equivalent to using Lua to perform DOM operations. I believe there must be a ready-made DOM library on the Internet. You can write one if you don’t have one yourself. Second question, I don’t know much about it

phpcn_u1582

I am going to try to use lua-resty-http or ngx.location.capture to send a request, modify the returned result, and then return the data

为情所困

If you are simply doing replacement, you can use Nginx’s ngx_http_sub_module module

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template