是否可以使用 apache 在一组 nodejs 服务器之间进行负载平衡?我还需要使用证书配置 apache 以提供 ssl 并且仅提供 https 请求。
简单的设置是 2 个作为我的负载平衡器的 Apache 服务器。所有请求都将通过 https 进入这 2 个负载平衡器之一。
负载均衡器需要从那里确定将请求路由到哪个服务器。这将是全部运行相同 Node 进程的 6 个服务器之一。
我知道有 mod_cluster,但我只在 JBoss 设置中使用过它,不确定它是否适用于 nodejs 服务器。
我也意识到这可能不是最好的设置,因为 Node 是单线程的,我可以尝试像 Node 集群这样的东西。然而, Node 集群似乎是垂直扩展而不是水平扩展。
我也知道有 nginx 和 haproxy,尽管我从未使用过它们中的任何一个并且对 apache 有更多的经验。也不确定 haproxy 和 nginx 是否支持只允许带有证书的 ssl 连接。
这种类型的负载平衡是否可以通过 apache 实现?如果可以,如何实现?
最佳答案
如果您使用 mod_proxy 模块,apache 的使用与后面使用的服务器无关。因此,您还可以查看所有使用 mod_proxy 的 apache->tomcat 示例。
在询问如何做之后,我添加了以下示例:
<VirtualHost *:80>
ProxyRequests off
ServerName domain.com
<Proxy balancer://mycluster>
# WebHead1
BalancerMember http://10.176.42.144:80
# WebHead2
BalancerMember http://10.176.42.148:80
# Security "technically we aren't blocking
# anyone but this the place to make those
# chages
Order Deny,Allow
Deny from none
Allow from all
# Load Balancer Settings
# We will be configuring a simple Round
# Robin style load balancer. This means
# that all webheads take an equal share of
# of the load.
ProxySet lbmethod=byrequests
</Proxy>
# balancer-manager
# This tool is built into the mod_proxy_balancer
# module and will allow you to do some simple
# modifications to the balanced group via a gui
# web interface.
<Location /balancer-manager>
SetHandler balancer-manager
# I recommend locking this one down to your
# your office
Order deny,allow
Allow from all
</Location>
# Point of Balance
# This setting will allow to explicitly name the
# the location in the site that we want to be
# balanced, in this example we will balance "/"
# or everything in the site.
ProxyPass /balancer-manager !
ProxyPass / balancer://mycluster/
</VirtualHost>
关于node.js - 可以使用 apache 在 nodejs 服务器之间进行负载平衡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31800197/