2013-09-05 1 views
0

광택 3.0.3을 사용하고 있습니다. 바니시는 부하 분산 장치 뒤에 있습니다.광택 - IP 주소 용 바이 패스 캐시

특정 IP 주소의 광택 캐시를 무시하고 싶습니다. 연구를 한 후에, 나는 다음을 발견했다. 불행히도 작동하지 않습니다.

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

이것은 내가 무엇이 잘못되었는지 모르겠어요 varnishlog"6 VCL_acl c NO_MATCH passem"

에 나타납니다. 내가 생각할 수있는 유일한 것은 바니시가 들어오는 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 대신 부하 분산 장치의 IP 주소입니다 SessionOpen IP 주소를 참조하면 나도 몰라한다.

답변

1

예, client.ip는 실제 IP이며 헤더에 전달 된 것이 아닙니다. 대신 올바른 헤더 req.http.X-Real-IP을 사용해야합니다.

+0

에게 있습니다. 그다지 쉬운 것은 아니었지만 귀하의 게시물은 해결책을 찾기 위해 올바른 방향으로 나를 지적했습니다. – iPhrankie

4

바니시에서 "X-Real-IP""http.x-forwarded-for"은 문자열이고 "client.ip"은 개체입니다.

"X-Forwarded-For" 헤더의 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); 
      } 
    }