mirror of
https://git.oxeozero.it.com/oxeo0/selfhosting-blogposts.git
synced 2025-05-18 08:50:21 -04:00
add selfhosting tutorials
This commit is contained in:
parent
95c33c8b41
commit
cc3824e6a2
1900 changed files with 32727 additions and 0 deletions
BIN
nginx_loadb/1.png
Normal file
BIN
nginx_loadb/1.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 4 KiB |
BIN
nginx_loadb/2.png
Normal file
BIN
nginx_loadb/2.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.5 KiB |
BIN
nginx_loadb/3.png
Normal file
BIN
nginx_loadb/3.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.9 KiB |
103
nginx_loadb/index.md
Normal file
103
nginx_loadb/index.md
Normal file
|
@ -0,0 +1,103 @@
|
|||
# NGINX Load Balancing
|
||||
|
||||
First off you will need a debian10 server to run nginx as a load balancer, and 2 other http servers.
|
||||
|
||||
## **Initial Setup**
|
||||
|
||||
First we're go install nginx:
|
||||
|
||||
|
||||
apt update -y && apt upgrade -y
|
||||
apt install nginx -y
|
||||
|
||||
|
||||
|
||||
Then you will need 2 http servers (mine are 192.168.0.150:80 and 192.168.0.151:80):
|
||||
|
||||

|
||||
|
||||
Then make the configuration to load balance the 2 servers:
|
||||
|
||||
|
||||
nano /etc/nginx/sites-available/loadb.conf
|
||||
|
||||
|
||||
|
||||
|
||||
upstream backend {
|
||||
server 192.168.0.150:80 weight=1;
|
||||
server 192.168.0.151:80 weight=2;
|
||||
|
||||
}
|
||||
server {
|
||||
listen 80;
|
||||
listen [::]:80;
|
||||
location / {
|
||||
proxy_pass http://backend;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Hit CTRL+S to save and CTRL+X to exit nano.
|
||||
|
||||
## **Launching the config**
|
||||
|
||||
Now remove the default config and launch reload nginx:
|
||||
|
||||
|
||||
|
||||
rm /etc/nginx/sites-available/default
|
||||
rm /etc/nginx/sites-enabled/default
|
||||
|
||||
ln -s /etc/nginx/sites-available/loadb.conf /etc/nginx/sites-enabled/loadb.conf
|
||||
nginx -s reload
|
||||
|
||||
|
||||
|
||||

|
||||
|
||||
And test if it load balances well. It should give us the output of the .151 server because it has the highest weight:
|
||||
|
||||

|
||||
|
||||
As you can see, nginx determines the number of allowed requests to each load balanced website with the weight parameter, for instance, our .151 server has a weight of 2, so nginx will allow us 2 requests before switching back to the .150 server.
|
||||
|
||||
This is also possible with other ports like database servers:
|
||||
|
||||
|
||||
upstream sqlbackend {
|
||||
server 192.168.0.150:3386 weight=1;
|
||||
server 192.168.0.151:3386 weight=2;
|
||||
|
||||
}
|
||||
server {
|
||||
listen 3386;
|
||||
listen [::]:3386;
|
||||
location / {
|
||||
proxy_pass sqlbackend;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
It is also possible to do with UDP:
|
||||
|
||||
|
||||
stream {
|
||||
upstream ntp {
|
||||
server 192.168.0.150:123 weight=2;
|
||||
server 192.168.0.151:123 weight=3;
|
||||
|
||||
}
|
||||
server {
|
||||
listen 123 udp;
|
||||
listen [::]:123 udp;
|
||||
location / {
|
||||
proxy_pass ntp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Here you can see how flexible nginx truly is, it can handle load balancing of multiple types of services, apply weights parameters over tcp/udp services.
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue