what about varnish cache ? how to clustering nodebb when we use varnish ?
with nodeBB tutorials we have something like this for varnish:
vcl 4.0;
backend nodebb {
.host = "127.0.0.1";
.port = "4567";
.connect_timeout = 1s;
.first_byte_timeout = 2s;
.between_bytes_timeout = 60s;
.max_connections = 10000;
}
backend forum {
.host = "127.0.0.1";
.port = "8082";
.connect_timeout = 5s;
.first_byte_timeout = 30s;
.between_bytes_timeout = 60s;
.max_connections = 100000;
}
import std;
sub vcl_recv {
unset req.http.X-Forwarded-For;
set req.http.X-Forwarded-For = client.ip;
set req.http.Host = regsub(req.http.Host, ":[0-9]+", "");
# Pipe websocket connections directly to Node.js
if (req.http.Upgrade ~ "(?i)websocket") {
set req.backend_hint = nodebb;
return (pipe);
}
if (req.http.host ~ "(?i)^(www.)?forum\.sanatisharif\.ir$")
{
set req.backend_hint = forum;
if (req.url ~ "^/socket.io/") {
set req.backend_hint = nodebb;
return (pipe);
}
return (pass);
}
...
...
}
sub vcl_pipe {
# Need to copy the upgrade header
if (req.http.upgrade) {
set bereq.http.upgrade = req.http.upgrade;
}
}
....
nginx:
upstream io_nodes {
ip_hash;
server 127.0.0.1:4567;
server 127.0.0.1:4568;
server 127.0.0.1:4569;
}
server {
listen 8082;
server_name community.nodebb.org;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_redirect off;
# Socket.io Support
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
gzip on;
gzip_min_length 1000;
gzip_proxied off;
gzip_types text/plain application/xml application/x-javascript text/css application/json;
location @nodebb {
proxy_pass http://io_nodes;
}
location ~ ^/(images|language|sounds|templates|uploads|vendor|src\/modules|nodebb\.min\.js|stylesheet\.css|admin\.css) {
root /path/to/nodebb/public/;
try_files $uri $uri/ @nodebb;
}
location / {
proxy_pass http://io_nodes;
}
}
NodeBB config:
{
"port": ["4567", "4568", "4569"] // will start three processes
}