1 개요[ | ]
- Varnish 스티키 세션 설정
- 클라이언트 웹브라우저에 'sticky'라는 쿠키변수를 만들어 추후 같은 백엔드로 연결되게 함
- 아래 예시에는 쿠키 만료기간
Expires
값이60m
으로 되어 있음
- 즉, 최초 접속으로부터 60분 후에는 다른 백엔드로 연결되어 세션데이터가 사라질 수 있음
- 쿠키 만료기간은 취향(?)에 따라 조정하면 됨
Python
Copy
vcl 4.0;
import std;
import directors;
import cookie;
import header;
backend server1 {
.host = "192.168.0.10";
.port = "8080";
}
backend server2 {
.host = "192.168.0.11";
.port = "8080";
}
sub vcl_init {
new hdir = directors.hash();
hdir.add_backend(server1, 1);
hdir.add_backend(server2, 1);
}
sub vcl_recv {
cookie.parse(req.http.cookie);
if(!cookie.isset("sticky")) {
set req.http.sticky = std.random(1, 4);
cookie.set("sticky", req.http.sticky);
}
set req.http.X-Forwarded-For = client.ip;
set req.backend_hint = hdir.backend(cookie.get("sticky"));
}
sub vcl_deliver {
if (req.http.sticky) {
header.append(resp.http.Set-Cookie, "sticky=" + req.http.sticky
+ "; Expires=" + cookie.format_rfc1123(now, 60m) + ";");
}
}
2 같이 보기[ | ]
3 참고[ | ]
편집자 Jmnote Jmnote bot
로그인하시면 댓글을 쓸 수 있습니다.