2013-09-05 2 views
4

Nginx를 간단한 역방향 프록시 캐시로 실행 중이므로 수신 한 응답 (헤더가 아닌 본문)에 따라 일부 헤더를 설정하려고합니다.Nginx : 캐시를 사용한 응답 처리 및 역방향 프록시

Lua는 location_capture_by를 사용하는 것이 간단 해 보이지만 캐싱이 제대로 작동하지 않는 것 같습니다.

초기 설정했다 : 나는 모든을 잃은 것을 발견 한 것은


location /{ 
content_by_lua ' 
    local res = ngx.location.capture(
       "/new-location", 
       { method = ngx.HTTP_POST, body = ngx.var.request_body}) 
    #update response body here and header etc based on content 
     ngx.say(res.body) 
     '; } 

location new-location{ 
try_files $uri @upstream_server 
} 

location @upstream_server { 
     proxy_pass "http://web_lb;" 
     proxy_cache small; 
     proxy_cache_methods POST; 
     proxy_cache_key "$request_uri|$request_body"; 
     client_max_body_size 500M; 
     add_header X-Cached $upstream_cache_status; 
     set_real_ip_from 10.86.102.0/24; 
     real_ip_header  X-Forwarded-For; 
     proxy_ignore_headers Set-Cookie; 
     proxy_ignore_headers Cache-Control; 
} 

====== :

location/{ 
.. 
try_files $uri @upstream_server 
} 

location @upstream_server { 
     proxy_pass "http://web_lb"; 
     proxy_cache small; 
     proxy_cache_methods POST; 
     proxy_cache_key "$request_uri|$request_body"; 
     client_max_body_size 500M; 
     add_header X-Cached $upstream_cache_status; 
     set_real_ip_from 10.86.102.0/24; 
     real_ip_header  X-Forwarded-For; 
     proxy_ignore_headers Set-Cookie; 
     proxy_ignore_headers Cache-Control; 
} 

가 그것을 변경 원래 헤더는 upstream_cache_status 헤더를 포함하여 Proxy_Header 처리의 일부로 추가 된 헤더입니다. 그러나 Nginx는 여전히 캐시 자체에서 반복되는 요청을 처리합니다.

왜 이렇게 될까요? 또한 나는 초기 초보자이기 때문에 약간의 기본적인 문제에 대해서는 변명의 여지가있다.

답변

0

사실, location.capture는 당신이하는 일을하기 위해 설계된 것이 아니지만 올바른 경우 (브라우저가 부역으로 보내는 헤더를 보내려는 경우) 아마도 ngx.ctx를 사용하여 해킹 할 수 있습니다 + 세트;)

그러나 나는 그것이 매우 더러운 kludgy 길이다라고 말하고 싶다.

관련 문제