简体   繁体   中英

Should I use both Nginx AND HAProxy for production node app?

I have a node/express/postgres app. I have the postgres db on one node and I plan to have several application nodes behind a separate load balancer so I can scale horizontally.

I set up my application nodes to each run nginx in front of the node app. So I have nginx listening on port 80 and forwarding the web requests to the node app on the same box which is listening on port 3000.

Then I was planning to put HAProxy in the front to handle the SSL termination and load balancing across the application nodes

My question: Is nginx obsolete in this case? Would it be better to just have HAProxy just forward to the application nodes on port 3000?

Are there any benefits of having nginx on each of the application nodes? I wont be serving any static files. My node app is a REST api that only returns JSON data. The node app doesn't ever render or serve any html.

In this case Nginx and HAProxy both serve the same purpose: isolating the non-battle hardened node http server stack (and lets face it, your node app is essentially a http server like Nginx or Apache but written by yourself) from the rest of the internet by proxying through battle-hardened http servers. Which means in this case having two http proxies in front of node is redundant.

However, there may be cases where you may want to do this. If your node servers live on clusters of machines and they all have access to the internet and they can all be accessed from the internet, then you may want to protect each machine with another http proxy like Nginx or Apache or lighttpd.

Generally though, you can protect the machines using firewalls. But sometimes it makes sense to expose each machine directly to the web.

I would just use HAProxy to proxy to the application nodes.

Having Nginx would be adding another potential point of failure and HAProxy has to health check both Nginx and node.js to ensure they are healthly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM