简体   繁体   English

POST请求的清漆缓存

[英]varnish caching of POST requests

What I'm doing is mildly insane, but since GET requests have very strict size limit, solr uses POST requests to /solr/select URL to do what is "semantically" a GET. 我正在做的事情有点疯狂,但是由于GET请求具有非常严格的大小限制,因此solr使用POST请求对/solr/select URL进行“语义上”的操作。

I'm trying to put varnish in front of solr to do some caching. 我试图将清漆放在solr前面进行一些缓存。 I put this in vcl_recv function: 我把它放在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);
 }

and varnish now tries to handle that except it automatically converts a POST to a GET. 并且清漆现在尝试处理该问题,除了它会自动将POST转换为GET。

I'm aware all of that is fairly ridiculous and far from any best practices, but in any case, is there an easy way to use varnish this way? 我知道所有这些都是很荒谬的,与最佳实践相去甚远,但是无论如何,有没有一种简单的方法可以使用这种清漆?

I got it working after reading this tutorial from . 阅读了本教程后,我可以使用它。

What the tutorial doesn't say is that there is a bug in one of the required VMODS when using with Varnish 4.1, this bug has the effect that the first POST request is passed to the backend with a truncated body. 教程没有说的是,与Varnish 4.1一起使用时,必需的VMODS之一中存在错误,该错误的结果是第一个POST请求以截断的正文传递给后端。

I solved this by using Varnish 5 and works like a charm. 我通过使用Varnish 5解决了这一问题,并且像魅力一样工作。

If you want to give it a try I have a Dockerfile for this: 如果您想尝试一下,我有一个Dockerfile:

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 start.sh

#!/bin/sh
set -xe

varnishd -a :80 -f /etc/varnish/default.vcl -s malloc,256m
varnishlog

You could try changing the req.POST into a GET, and transform the POST data to GET parameters (you probably would have to use inline-C) and do a lookup / fetch. 您可以尝试将req.POST更改为GET,然后将POST数据转换为GET参数(您可能必须使用inline-C)并执行查找/获取。

This GET request limit from the HTTP spec is not necessarily implemented by either Varnish or your back-end server. HTTP规范中的GET请求限制不一定由Varnish或您的后端服务器实现。 As you don't depend on intermediate caches and User-Agents outside your control to handle long urls, you could give it a try. 由于您不依赖控件之外的中间缓存和User-Agent处理长网址,因此可以尝试一下。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM