How to configure Nginx load balance with Hestia?

Hello guy,

I want configure load balance with Nginx:

I have 3 VPS installed Hestia,

and a domain.com, I want to distribute traffic randomly,

Hestia issn’t suitable for it… You will get issues with database and sessions…

Ok I understand that I get issues with database and session,

But please show me some example which I can use with hestia

You can use one server for static content. And the other for the web.

You can try this… but hestia does no good.

http://nginx.org/en/docs/http/load_balancing.html

Hi,
I already doing same static content on other cdn server and website on other server,
but due to heavy load, I want to load balance, but after hearing from hestia team and also same thing from the web script Team, that not possible load balance, I am crying… :sob: :sob: :sob: :cry: :cry: :cry:

because after long time my website growing, and now its downing

This is unrelated but. Maybe you should analyse if all your traffic is legitimate or you are suffering from hack attempts that are consuming your resources.

Hestia is not designed to be load balanced over multiple server.

If you have the need to use a load balancer it make sense to split the tasks first:

  1. Split web server and database
  2. Offload static files to static server
  3. Then it make sense to use multiple servers but even then the “usefullness” for Hestia is limited to 0…

It makes more sense to setup it manully and use a deploy software for it…

As others have already stated Hestia can not help you with load balancing out of the box but won’t get in your way either. Every load balancing solution that nginx supports, should be possible in hestia too, using custom templates.

Presuming you have a Nginx+Apache setup on every Hestia install: Here you have a diff from the default.tpl nginx proxy template to enable load balancing.
(/usr/local/hestia/data/templates/web/nginx/default.tpl)

--- default.tpl	2020-11-07 00:53:03.770079790 +0000
+++ lb-mywebsite.tpl	2021-07-18 12:56:13.232115435 +0000
@@ -3,6 +3,11 @@
 # DO NOT MODIFY THIS FILE! CHANGES WILL BE LOST WHEN REBUILDING DOMAINS #
 #=======================================================================#
 
# upstream section on server 01
+upstream mywebsite_backend_http {
+    server %ip%:%web_port%;
+    # server 192.168.0.50;                # change with server 01 ip
+    server 192.168.0.60;                # change with server 02 ip
+    server 192.168.0.70;                # change with server 03 ip
+}
+
 server {
     listen      %ip%:%proxy_port%;
     server_name %domain_idn% %alias_idn%;
@@ -10,7 +15,7 @@
     include %home%/%user%/conf/web/%domain%/nginx.forcessl.conf*;
 
     location / {
-        proxy_pass      http://%ip%:%web_port%;
+        proxy_pass      http://mywebsite_backend_http;
         location ~* ^.+\.(%proxy_extentions%)$ {
             root           %docroot%;
             access_log     /var/log/%web_system%/domains/%domain%.log combined;
@@ -25,7 +30,7 @@
     }
 
     location @fallback {
-        proxy_pass      http://%ip%:%web_port%;
+        proxy_pass      http://mywebsite_backend_http;
     }
 
     location ~ /\.ht    {return 404;}

Note: every vps must have a different upstream block, ex:

and also you have to adapt the snippet for HTTP
Additionally you can/shoul add all the vps ip addresses to the domain DNS record (DNS round robin) with a 300s TTL

# on vps server 01:
upstream mywebsite_backend_http {
    server %ip%:%web_port%;
    server 192.168.0.60;                # change with server 02 ip
    server 192.168.0.70;                # change with server 03 ip
}

---

# on vps server 02:
upstream mywebsite_backend_http {
    server 192.168.0.50;                # change with server 01 ip
    server %ip%:%web_port%;
    server 192.168.0.70;                # change with server 03 ip
}

---

# on vps server 03:
upstream mywebsite_backend_http {
    server 192.168.0.50;                # change with server 01 ip
    server 192.168.0.60;                # change with server 02 ip
    server %ip%:%web_port%;
}

Final note: Webserver load balancing is just a piece of the puzzle, session, databases and file sync need be treated carefully, otherwise doing just this will be pointless.

References:

2 Likes