gpt4 book ai didi

Varnish -IP地址的旁路缓存

转载 作者:行者123 更新时间:2023-12-03 17:47:05 27 4
gpt4 key购买 nike

我们正在使用Varnish 3.0.3。 Varnish 位于负载均衡器的后面。

我们想绕过特定IP地址的Varnish缓存。经过研究,我发现了以下内容。不幸的是,它不起作用。

    acl passem { "7x.xxx.xxx.xxx"; }
sub vcl_recv {
if (!(client.ip ~ passem)) {
return (pass);
}
}

这出现在 varnishlog "6 VCL_acl c NO_MATCH passem"

我不确定这是怎么回事。我唯一能想到的是Varnish没有看到传入的IP地址。这是我在 varnishlog中看到的。
    6 RxHeader     c X-Real-IP: "7x.xxx.xxx.xxx"
6 RxHeader c X-Forwarded-For: "7x.xxx.xxx.xxx"

6 SessionOpen c 10.10.10.4 58143 0.0.0.0:80
6 ReqStart c 10.10.10.4 58143 1026834560

RxHeader正在接收正确的IP并匹配 acl passem,但是我不知道 acl passem是否引用了 SessionOpen IP地址,即负载均衡器的IP地址。

最佳答案

在 Varnish 中,"X-Real-IP""http.x-forwarded-for" 是字符串,"client.ip" 是一个对象。

需要额外的代码来将 "X-Forwarded-For" header 中的 IP 地址复制到 Varnish 的 client_ip 结构中。

以下是使其工作所需的条件。这工作成功。归功于 http://zcentric.com/2012/03/16/varnish-acl-with-x-forwarded-for-header/

    C{
#include <netinet/in.h>
#include <string.h>
#include <sys/socket.h>
#include <arpa/inet.h>
}C
acl passem { "7x.xxx.xxx.xxx"; }
sub vcl_recv {
C{
struct sockaddr_storage *client_ip_ss = VRT_r_client_ip(sp);
struct sockaddr_in *client_ip_si = (struct sockaddr_in *) client_ip_ss;
struct in_addr *client_ip_ia = &(client_ip_si->sin_addr);
char *xff_ip = VRT_GetHdr(sp, HDR_REQ, "\020X-Forwarded-For:");

if (xff_ip != NULL) {
inet_pton(AF_INET, xff_ip, client_ip_ia);
}
}C
if (!(client.ip ~ passem)) {
return (pass);
}
}

关于 Varnish -IP地址的旁路缓存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18645182/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com