【问题标题】:varnish caching of POST requests清漆缓存 POST 请求
【发布时间】:2012-02-19 20:51:57
【问题描述】:

我正在做的事情有点疯狂,但由于 GET 请求有非常严格的大小限制,solr 使用对/solr/select URL 的 POST 请求来执行“语义上”的 GET 操作。

我正在尝试将清漆放在 solr 前面以进行一些缓存。我把这个放在vcl_recv函数中:

 if (!(req.request == "GET" || req.request == "HEAD" ||
     (req.request == "POST" && req.url == "/solr/select"))) {
     /* We only deal with GET and HEAD by default */
     /* Modified to support POST to /solr/select */
     return (pass);
 }

varnish 现在会尝试处理这个问题,只是它会自动将 POST 转换为 GET。

我知道所有这些都是相当荒谬的,并且与任何最佳实践相去甚远,但无论如何,有没有一种简单的方法可以以这种方式使用清漆?

【问题讨论】:

    标签: http solr varnish


    【解决方案1】:

    阅读此tutorial from 后我得到了它。

    本教程没有说明的是,在与 Varnish 4.1 一起使用时,其中一个所需的 VMODS 中存在一个错误,该错误的效果是第一个 POST 请求以截断的主体传递到后端。

    我使用 Varnish 5 解决了这个问题,而且效果很好。

    如果你想试一试,我有一个 Dockerfile:

    Dockerfile:

    FROM alpine:3.7
    
    LABEL maintainer lloiacono@*******.com
    
    RUN apk update \
        && apk add --no-cache varnish \
        && apk add git \
        && git clone https://github.com/varnish/varnish-modules.git \
        && apk add automake && apk add varnish-dev \
        && apk add autoconf && apk add libtool \
        && apk add py-docutils && apk add make \
        && cd varnish-modules/ \
        && ./bootstrap && ./configure && make && make install
    
    COPY start.sh /usr/local/bin/docker-app-start
    
    RUN chmod +x /usr/local/bin/docker-app-start
    
    CMD ["docker-app-start"]
    

    start.sh

    #!/bin/sh
    set -xe
    
    varnishd -a :80 -f /etc/varnish/default.vcl -s malloc,256m
    varnishlog
    

    【讨论】:

      【解决方案2】:

      您可以尝试将 req.POST 更改为 GET,并将 POST 数据转换为 GET 参数(您可能必须使用内联-C)并进行查找/获取。

      HTTP 规范中的 GET 请求限制不一定由 Varnish 或您的后端服务器实现。由于您不依赖于您无法控制的中间缓存和用户代理来处理长 url,因此您可以尝试一下。

      【讨论】:

      • 我还没有把它们放在一起,但是 Tomcat 有最大 HTTP 请求大小的配置参数,而且 solr 对 64kB 的 URL 很满意,所以它应该可以工作。
      猜你喜欢
      • 1970-01-01
      • 2016-02-12
      • 1970-01-01
      • 2017-10-20
      • 2013-01-09
      • 2015-10-10
      • 2020-07-26
      • 2018-08-13
      • 2021-05-09
      相关资源
      最近更新 更多