Question
How can I set up a Load Balancer for my Expressjs based application?
I’ve set up a load balancer that is picking up my droplets by tag, however, they are always showing as a status of “down”.
I am pointing the load balancer directly to my nodejs APIs, without Nginx or anything sitting in front. I also have an endpoint set up called “/health” which simply returns a status of 200, and the load balancer set to use that endpoint.
Below is the configuration for my Expressjs server.
app.set('trust proxy', true);
app.use(helmet());
app.use(cors());
app.use(passport.initialize());
app.get('/health', (req, res) => res.sendStatus(200));
app.use('/api', routes);
app.listen(PORT, () => {
console.log(
chalk.yellow(`Listening on *:${PORT}`)
);
});
My load balancer configuration is as follows
Forwarding rules
HTTP on port 80 HTTP on port 3000
HTTPS on port 443 HTTP on port 3000
Algorithm
Least Connections
Health checks
http://0.0.0.0:3000/health
Sticky sessions
Off
SSL
Redirect HTTP to HTTPS
Proxy Protocol
Enabled