Я сейчас настраиваю Varni sh 4 для моего домена для пост-запроса. Но я не могу понять, почему запрос всегда «MISS», и я получаю x-cache как passcacheable.
Varni sh Версия
varnishd (varnish-4.1.11 revision 61367ed17d08a9ef80a2d42dc84caef79cdeee7a)
Copyright (c) 2006 Verdens Gang AS
Copyright (c) 2006-2019 Varnish Software AS
Где мой VCL файл
vcl 4.0;
import std;
import bodyaccess;
backend default {
.host = "X.X.X.X";
.port = "80";
}
sub vcl_recv {
unset req.http.x-cache;
unset req.http.X-Body-Len;
if (req.method == "POST") {
std.log("Will cache POST for: " + req.http.host + req.url);
std.cache_req_body(3000KB);
set req.http.X-Body-Len = bodyaccess.len_req_body();
set req.http.Content-Length = bodyaccess.len_req_body();
if (req.http.X-Body-Len == "-1") {
return(synth(400, "The request body size exceeds the li$
}
return (hash);
}
}
sub vcl_hash {
# To cache POST and PUT requests
std.syslog(9,"vcl hash "+ req.http.X-Body-Len);
bodyaccess.hash_req_body();
}
sub vcl_backend_fetch {
if(bereq.http.X-Body-Len){
set bereq.method = "POST";
}
}
sub vcl_backend_response {
if (beresp.ttl <= 0s ||
beresp.http.Set-Cookie ||
beresp.http.Surrogate-control ~ "no-store" ||
(!beresp.http.Surrogate-Control &&
beresp.http.Cache-Control ~ "no-cache|no-store|private") ||
beresp.http.Vary == "*") {
/*
* Mark as "Hit-For-Pass" for the next 2 minutes
*/
set beresp.ttl = 120s;
set beresp.uncacheable = true;
}
return (deliver);
}
sub vcl_deliver {
std.syslog(9, "response status "+ resp.status);
}
sub vcl_hit {
set req.http.x-cache = "hit";
}
sub vcl_miss {
set req.http.x-cache = "miss";
}
sub vcl_pass {
set req.http.x-cache = "pass";
}
sub vcl_pipe {
set req.http.x-cache = "pipe uncacheable";
}
sub vcl_synth {
set resp.http.x-cache = "synth synth";
}
sub vcl_deliver {
if (obj.uncacheable) {
set req.http.x-cache = req.http.x-cache + " uncacheable" ;
} else {
set req.http.x-cache = req.http.x-cache + " cached" ;
}
set resp.http.x-cache = req.http.x-cache;
}
, если вы видите VarnishLog
32833 Link c req 32834 rxreq
32835 Begin b bereq 32834 pass
32835 Timestamp b Start: 1585506203.103807 0.000000 0.000000
32835 BereqMethod b POST
32835 BereqURL b /XYZ/
32835 BereqProtocol b HTTP/1.1
32835 BereqHeader b Content-Type: application/json
32835 BereqHeader b Accept-Language: en-US
32835 BereqHeader b User-Agent: PostmanRuntime/7.24.0
32835 BereqHeader b Accept: */*
32835 BereqHeader b Host: X.X.X.X
32835 BereqHeader b Content-Length: 161
32835 BereqHeader b X-Forwarded-For: Y.Y.Y.Y
32835 BereqHeader b X-Body-Len: 161
32835 BereqHeader b Accept-Encoding: gzip
32835 BereqHeader b x-cache: pass
32835 BereqHeader b X-Varnish: 32835
32835 VCL_call b BACKEND_FETCH
32835 BereqMethod b POST
32835 VCL_return b fetch
32835 Timestamp b Bereq: 1585506203.105855 0.002048 0.002048
32835 Timestamp b Beresp: 1585506205.155543 2.051736 2.049688
32835 BerespProtocol b HTTP/1.1
32835 BerespStatus b 200
32835 BerespReason b OK
32835 BerespHeader b Cache-Control: public, max-age=86400
32835 BerespHeader b Content-Type: application/json
32835 BerespHeader b Server: Microsoft-IIS/10.0
32835 BerespHeader b Access-Control-Allow-Origin: *
32835 BerespHeader b X-AspNet-Version: 4.0.30319
32835 BerespHeader b X-Powered-By: ASP.NET
32835 BerespHeader b Date: Sun, 29 Mar 2020 18:23:21 GMT
32835 BerespHeader b Content-Length: 1499
32835 TTL b RFC 86400 10 -1 1585506205 1585506205 1585506201 0 86400
32835 VCL_call b BACKEND_RESPONSE
32835 TTL b VCL 120 10 0 1585506205
32835 VCL_return b deliver
32835 Storage b malloc Transient
32835 ObjProtocol b HTTP/1.1
32835 ObjStatus b 200
32835 ObjReason b OK
32835 ObjHeader b Cache-Control: public, max-age=86400
32835 ObjHeader b Content-Type: application/json
32835 ObjHeader b Server: Microsoft-IIS/10.0
32835 ObjHeader b Access-Control-Allow-Origin: *
32835 ObjHeader b X-AspNet-Version: 4.0.30319
32835 ObjHeader b X-Powered-By: ASP.NET
32835 ObjHeader b Date: Sun, 29 Mar 2020 18:23:21 GMT
32835 ObjHeader b Content-Length: 1499
32835 Fetch_Body b 3 length stream
32835 BackendReuse b 24 boot.default
32835 Timestamp b BerespBody: 1585506205.155630 2.051823 0.000087
32835 Length b 1499
32835 BereqAcct b 343 161 504 318 1499 1817
32835 End b
32834 Begin c req 32833 rxreq
32834 Timestamp c Start: 1585506203.103709 0.000000 0.000000
32834 Timestamp c Req: 1585506203.103709 0.000000 0.000000
32834 ReqStart c Y.Y.Y.Y 50188
32834 ReqMethod c POST
32834 ReqURL c /XYZ/
32834 ReqProtocol c HTTP/1.1
32834 ReqHeader c Content-Type: application/json
32834 ReqHeader c Accept-Language: en-US
32834 ReqHeader c User-Agent: PostmanRuntime/7.24.0
32834 ReqHeader c Accept: */*
32834 ReqHeader c Host: X.X.X.X
32834 ReqHeader c Accept-Encoding: gzip, deflate, br
32834 ReqHeader c Connection: keep-alive
32834 ReqHeader c Content-Length: 161
32834 ReqHeader c X-Forwarded-For: Y.Y.Y.Y
32834 VCL_call c RECV
32834 Storage c malloc Transient
32834 Timestamp c ReqBody: 1585506203.103769 0.000060 0.000060
32834 Debug c "VRT_CacheReqBody(3072000): 161"
32834 ReqHeader c X-Body-Len: 161
32834 VCL_return c hash
32834 ReqUnset c Accept-Encoding: gzip, deflate, br
32834 ReqHeader c Accept-Encoding: gzip
32834 VCL_call c HASH
32834 VCL_return c lookup
32834 Debug c "XXXX HIT-FOR-PASS"
32834 HitPass c 32823
32834 VCL_call c PASS
32834 ReqHeader c x-cache: pass
32834 VCL_return c fetch
32834 Link c bereq 32835 pass
32834 Timestamp c Fetch: 1585506205.155654 2.051945 2.051885
32834 RespProtocol c HTTP/1.1
32834 RespStatus c 200
32834 RespReason c OK
32834 RespHeader c Cache-Control: public, max-age=86400
32834 RespHeader c Content-Type: application/json
32834 RespHeader c Server: Microsoft-IIS/10.0
32834 RespHeader c Access-Control-Allow-Origin: *
32834 RespHeader c X-AspNet-Version: 4.0.30319
32834 RespHeader c X-Powered-By: ASP.NET
32834 RespHeader c Date: Sun, 29 Mar 2020 18:23:21 GMT
32834 RespHeader c Content-Length: 1499
32834 RespHeader c X-Varnish: 32834
32834 RespHeader c Age: 0
32834 RespHeader c Via: 1.1 varnish-v4
32834 VCL_call c DELIVER
32834 ReqUnset c x-cache: pass
32834 ReqHeader c x-cache: pass uncacheable
32834 RespHeader c x-cache: pass uncacheable
32834 VCL_return c deliver
32834 Timestamp c Process: 1585506205.155707 2.051998 0.000053
32834 RespHeader c Accept-Ranges: bytes
32834 Debug c "RES_MODE 2"
32834 RespHeader c Connection: keep-alive
32834 Timestamp c Resp: 1585506205.155740 2.052032 0.000034
32834 ReqAcct c 299 161 460 438 1499 1937
32834 End c
0 CLI - Rd ping
0 CLI - Wr 200 19 PONG 1585506205 1.0
0 CLI - Rd ping
0 CLI - Wr 200 19 PONG 1585506208 1.0
32833 SessClose c RX_TIMEOUT 7.072
32833 End c
Как вы видите Отладка: "XXX HIT-FOR-PASS"
Это всегда происходит, даже если на бэкэнд-сервере установлен Cache-Control: publi c, max-age = 86400
Varni sh, конечная точка возвращает x-cache: pass uncacheable
Первый ответ 411 Требуется длина, тогда как последующий ответ успешен с 200 OK, но с X-Cache как «pass uncacheable».
Что я делаю неправильно?