문제
Nginx의 .conf 파일에서 $ memcached_keys가 너무 길어야합니다. MemCached 모듈을 사용하고 있지만 일부 URL이 너무 길다. 대신 URL의 MD5 해시를 사용하려고 노력하고 있지만 그 동안 변수에 저장된 문자열의 길이를 확인할 수있는 방법이 있는지 궁금했습니다.
그래서:
set $memcached_key "byp-$uri";
if ($args) {
set $memcached_key "byp-$uri?$args";
}
if (len($memcache_key) < 250) {
memcached_pass 127.0.0.1:11211;
error_page 404 = @cache_miss;
error_page 502 = @cache_miss;
}
else {
pass to @cache_miss;
}
해결책
나는 긍정적이지는 않지만 Nginx 구성 언어 내에서 수행 할 수 있다고 생각하지 않습니다. 나는 그것이 문서화 될 것이라고 생각한다 여기 그것이 존재한다면, 나는 아무것도 보지 못합니다.
다른 팁
오래된 질문이지만 ....
이런 종류의 작업을 수행하려면 LUA 모듈과 같은 스크립팅 설정이 필요합니다.
location / {
set_by_lua $memcached_key '
if not ngx.var.args then
return "byp-" .. ngx.var.uri
else
return "byp-" .. ngx.var.uri .. "?" .. ngx.var.args
end
';
content_by_lua '
local string = string;
if string.len($memcached_key) < 250 then
ngx.exec("/memcached");
else
ngx.exec("/cache_miss");
end
';
}
location /memcached {
internal;
memcached_pass 127.0.0.1:11211;
error_page 404 = /cache_miss;
error_page 502 = /cache_miss;
}
location /cache_miss {
internal;
...
}
후자의 몇 가지 단점으로 인해 이름이 지정된 위치 대신 "내부"위치를 제안하지만 명명 된 위치도 사용할 수 있습니다.
제휴하지 않습니다 StackOverflow