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는 여전히 캐시 자체에서 반복되는 요청을 처리합니다.
왜 이렇게 될까요? 또한 나는 초기 초보자이기 때문에 약간의 기본적인 문제에 대해서는 변명의 여지가있다.