清漆4磅以上-绕过特定IP地址的缓存

我正在尝试将Varnish配置为不对特定IP使用缓存。

我已在 Centos 上使用 pound Apache 上配置了 Centos Varnish 4

>

我尝试遵循这种方法:

Varnish - Bypass Cache for IP Address

基于

https://zcentric.com/2012/03/16/varnish-acl-with-x-forwarded-for-header/

使用一些C代码来管理IP。建议的代码适用于Varnish3(例如,“ sp”已经不存在,现在有一个ctx变量)

我尝试使用此方法Inline C Varnish (VCL_deliver),但是在结构sockaddr_storage client_ip_ss = VRT_r_client_ip(ctx);“ 错误中,从不兼容的指针类型[-Werror]初始化了*”可能是因为类型也已更改。

我要使用的代码是:

struct sockaddr_storage *client_ip_ss = VRT_r_client_ip(ctx); 
struct sockaddr_in *client_ip_si = (struct sockaddr_in *) client_ip_ss; 
struct in_addr *client_ip_ia = &(client_ip_si->sin_addr); 
const struct gethdr_s hdr = { HDR_REQ,"20X-Forwarded-For:" }; 
char *xff_ip = VRT_GetHdr(ctx,&hdr);

但是我做错了事。

我现在迷路了,如何在Varnish 4上为特定IP禁用清漆?

谢谢

huanglianxing 回答:清漆4磅以上-绕过特定IP地址的缓存

请不要在Varnish中编写内联C代码:这很冒险,您正在寻找的解决方案已经在Varnish中自动实现。

请记住,不再支持Varnish v3和v4,请使用Varnish 6

清漆会自动设置X-Forwarded-For标头

如果您要基于X-Forwarded-For值从缓存中排除项目,则仍然可以使用client.ip并将该值与acl匹配。

Varnish将自动从其客户端获取IP并将其存储在X-Forwarded-For标头中。这意味着client.ip的值与req.http.X-Forwarded-For完全相同。

多个代理和代理协议

在使用Varnish之前使用其他代理时,您必须确保它们通过 PROXY协议进行通信。 Varnish支持PROXY协议,您的其他代理也应支持。

在您的情况下为英镑。 Varnish社区建议Hitch终止TLS。

在Varnish中启用PROXY协议支持是通过打开特定的侦听地址来完成的:

varnishd -a :80 -a :8443,PROXY

然后,Varnish可以通过PROXY协议接受端口8443上的连接。

使用PROXY协议的主要优点是原始客户端IP地址一直传输到Varnish。无论Varnish前面有多少代理,client.ip值始终是原始客户端的IP地址。

如果Pound不支持PROXY协议,我建议您切换到Hitch

定义ACL

一旦您设置了具有PROXY协议支持的TLS终止,就可以编写一些VCL来传递来自缓存的项目,如下所示:

acl passem { "7x.xxx.xxx.xxx"; }
sub vcl_recv {
  if (!(client.ip ~ passem)) {
    return (pass);
  }
}
本文链接:https://www.f2er.com/2589021.html

大家都在问