作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我们正在使用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"
中
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
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/
我是一名优秀的程序员,十分优秀!