可以使用 apache 跨 nodejs 服务器进行负载平衡

los*_*ion 2 apache ssl https load-balancing node.js

是否可以使用 apache 在一组 nodejs 服务器之间进行负载平衡?我还需要使用证书配置 apache 以提供 ssl 并且只提供 https 请求。

简单的设置是 2 个 apache 服务器,它们将成为我的负载平衡器。所有请求都将通过 https 进入这两个负载均衡器之一。

从那里负载平衡器需要确定将请求路由到哪个服务器。这将是运行相同节点进程的 6 台服务器之一。

我知道有 mod_cluster,但我只在 JBoss 设置中使用过它,并不确定这是否适用于 nodejs 服务器。

我也意识到这可能不是最好的设置,因为节点是单线程的,我可以尝试像节点集群这样的东西。然而,节点集群似乎是垂直扩展而不是水平扩展。

我也知道有 nginx 和 haproxy,尽管我从未使用过它们中的任何一个,并且对 apache 有更多的经验。也不确定 haproxy 和 nginx 是否支持只允许使用证书的 ssl 连接。

这种类型的负载平衡是否可以使用 apache,如果可以,如何实现?

Ali*_*nex 5

如果使用 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>
Run Code Online (Sandbox Code Playgroud)