Made some changes to the way nodebb works in order to fix socket.io on cluster.
This only effects people who are using the "cluster"
setting in config.json.
cluster
setting has been removed in latest master, in order to spawn more than one nodebb process you have to add a port
property into config.json. I'll post some samples below.
NodeBB with a single process. Listening on port 4567, no port property required.
{
"url": "http://yournodebb.com:4567",
"secret": "secretsauce",
"database": "redis",
"redis": {
"host": "127.0.0.1",
"port": "6379",
"username": "",
"password": "",
"database": "0"
}
}
NodeBB with 4 processes on ports 4567, 4568, 4569, 4570
{
"url": "http://yournodebb.com",
"port": ["4567", "4568", "4569", "4570"],
"secret": "secretsauce",
"database": "redis",
"redis": {
"host": "127.0.0.1",
"port": "6379",
"username": "",
"password": "",
"database": "0"
}
}
If you specify multiple ports you need to setup a load balancer like nginx to proxy requests to these ports. Here is a sample nginx.conf that does that for the above config.json
server {
listen 80;
server_name yournodebb.com;
location / {
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_pass http://io_nodes;
proxy_redirect off;
# Socket.IO Support
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}
upstream io_nodes {
ip_hash;
server 127.0.0.1:4567;
server 127.0.0.1:4568;
server 127.0.0.1:4569;
server 127.0.0.1:4570;
}
The above nginx config will proxy requests to nodebb instances based on their ip, this is important for socket.io since polling doesn't work if requests during handshake go to different processes.
relevant commits
https://github.com/NodeBB/NodeBB/commit/64e13df14cd8ca5364e5e465926d49b1c2ca2654
https://github.com/NodeBB/NodeBB/commit/d62cdd5127bde78ba4b5c1f5e50ab05dc8ccd519
Let me know if you have any questions.