Nginx : Load Balancing2019/08/08 |
Configure Nginx as a Load Balancing Server.
This example is based on the environment like follows. -----------+---------------------------+----- | | |10.0.0.30 | +----------+-----------+ | | [ www.srv.world ] | | | Nginx | | +----------------------+ | | ------------+--------------------------+--------------------------+------------ | | | |10.0.0.51 |10.0.0.52 |10.0.0.53 +-----------+----------+ +-----------+----------+ +-----------+----------+ | [ node01.srv.world ] | | [ node02.srv.world ] | | [ node03.srv.world ] | | Web Server#1 | | Web Server#2 | | Web Server#3 | +----------------------+ +----------------------+ +----------------------+ |
[1] | Configure Nginx. |
root@www:~#
vi /etc/nginx/nginx.conf # add into [http] section # [backup] means this server is balanced only when other servers are down # [weight=*] means balancing weight
http {
upstream backends {
server node01.srv.world:80 weight=2;
server node02.srv.world:80;
server node03.srv.world:80 backup;
}
root@www:~#
vi /etc/nginx/sites-available/default # change like follows in [server] section
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name www.srv.world;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
location / {
proxy_pass http://backends;
}
}
root@www:~# systemctl restart nginx |
[2] | Verify it works fine to access to frontend Nginx from any Client Host with HTTP. |
Sponsored Link |
|