第26章 配置 Varnish Cache
配置 Varnish 缓存
为确保 Varnish 能与 NodeBB 正常协作,请检查配置文件 `/etc/varnish/default.vcl` 是否针对 websockets 进行了优化。
backend nodebb { .host = "127.0.0.1"; # your nodebb host .port = "4567"; # your nodebb port }
sub vcl_recv {
# Pipe websocket connections directly to Node.js if (req.http.Upgrade ~ "(?i)websocket") { set req.backend = nodebb; return (pipe); }
# NodeBB if (req.http.host == "forum.yourwebsite.com") { # change this to match your host if (req.url ~ "^/socket.io/") { set req.backend = nodebb; return (pipe); # return pass seems not working for websockets } return (pass); # don't cache }
}
sub vcl_pipe { # Need to copy the upgrade header if (req.http.upgrade) { set bereq.http.upgrade = req.http.upgrade; } }