Complete the code to define a basic load balancer using NGINX.
upstream backend {
server [1];
}
server {
listen 80;
location / {
proxy_pass http://backend;
}
}The server directive inside upstream defines the backend server address. Using 127.0.0.1:8080 is a common local backend example.
Complete the code to set the load balancing method to round robin.
upstream backend {
# [1];
server 127.0.0.1:8080;
server 127.0.0.1:8081;
}The default load balancing method in NGINX is round robin, but explicitly setting round_robin clarifies the method used.
Fix the error in the load balancer configuration to enable sticky sessions.
upstream backend {
[1];
server 192.168.0.10;
server 192.168.0.11;
}To enable sticky sessions in NGINX, the ip_hash directive is used to route clients to the same server based on their IP.
Fill both blanks to configure weighted load balancing for two servers.
upstream backend {
server 10.0.0.1 weight=[1];
server 10.0.0.2 weight=[2];
}Weights control how much traffic each server receives. A weight of 5 sends more traffic than a weight of 1.
Fill all three blanks to create a health check for backend servers.
server {
listen 80;
location / {
proxy_pass http://backend;
proxy_next_upstream [1];
proxy_connect_timeout [2]s;
proxy_read_timeout [3]s;
}
}proxy_next_upstream defines when to try the next server. Timeouts control connection and read wait times.