Should I use Nginx and HAProxy to create a node application?

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

I have set my app nodes for each nginx run in front of the node app. So I am listening on nginx on port 80 and redirecting web requests to the node application in the same window that is listening on port 3000.

Then I planned to enable HAProxy in front to handle SSL termination and load balancing across application nodes

My question is, is nginx deprecated in this case? Would it be better if only HAProxy would just forward the application hosts to port 3000?

Are there any advantages of having nginx for each of the application nodes? I will not serve static files. My node app is a REST api that only returns JSON data. The node app never outputs or serves up any html.

+3


source to share


2 answers


In this case, Nginx and HAProxy both serve the same purpose: to isolate the non-bit hardened node stack of the http server (and looking at it, your node application is essentially an http server like Nginx or Apache but self-written) from the rest of the internet, proxying through server-hardened HTTP servers. This means that in this case, having two HTTP proxies in front of the node is redundant.

However, there may be times when you can do this. If your node servers live on clusters of machines and they all have internet access and can be accessed from the internet, then you can secure each machine with a different HTTP proxy like Nginx or Apache or lighttpd.



In general, you can protect machines using firewalls. But sometimes it makes sense to expose each machine directly on the Internet.

+2


source


I would just use HAProxy to proxy for application nodes.



If Nginx adds another potential point of failure, then HAProxy has to test the health of both Nginx and node.js to ensure they are functional.

+1


source







All Articles