【问题标题】:replacing content in a page with varnish + regex用清漆+正则表达式替换页面中的内容
【发布时间】:2013-03-26 19:20:30
【问题描述】:

如果我希望清漆缓存服务器在提供或存储页面(vcl_fetch?)之前从后端替换页面内的内容(即:更改 div 上的类),该怎么做?

我想使用简单的正则表达式来执行替换,因为我想它在 varnish 中本机支持。

【问题讨论】:

    标签: regex caching webserver varnish varnish-vcl


    【解决方案1】:

    Varnish 本身不支持修改响应正文。为此,您需要一个 Varnish 模块 (vmod)。

    Aivars Kalvans 有 libvmod-rewrite,它完全符合您的要求。然而,vmod 是一个概念证明,根据 Aivars 的说法,它还没有准备好用于生产。在任何情况下,您都可以将其作为起点。

    如果您使用的是 Apache,您可以使用 mod_ext_filter 来修改响应正文。这是 mod_ext_filters 文档中的一个示例。由于您可以将响应正文传递给任何外部命令,因此很容易对内容进行必要的修改。

    # mod_ext_filter directive to define a filter which
    # replaces text in the response
    #
    ExtFilterDefine fixtext mode=output intype=text/html cmd="/bin/sed s/verdana/arial/g"
    
    <Location />
    # core directive to cause the fixtext filter to
    # be run on output
    SetOutputFilter fixtext
    </Location> 
    

    【讨论】:

    • 最后只是在上漆之前编写了我自己的 passthrough。不过我会看看 libvmod-rewrite 。谢谢。
    • 关于 mod_ext_filters 我认为如果 apache 是一个选项,mod_substitute 可能更适合用例
    猜你喜欢
    • 2016-03-27
    • 2018-10-13
    • 1970-01-01
    • 2017-02-21
    • 1970-01-01
    • 2016-04-06
    • 1970-01-01
    • 1970-01-01
    • 2018-01-07
    相关资源
    最近更新 更多