search

Home  >  Q&A  >  body text

In an Nginx+Lua environment, how to replace part of the response data before returning it?

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?

阿神阿神2754 days ago765

reply all(3)I'll reply

  • 滿天的星座

    滿天的星座2017-05-16 17:14:34

    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

    reply
    0
  • phpcn_u1582

    phpcn_u15822017-05-16 17:14:34

    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

    reply
    0
  • 为情所困

    为情所困2017-05-16 17:14:34

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

    reply
    0
  • Cancelreply