Balanceo de carga ponderado y servidores de respaldo
Distribuya el tráfico de forma desigual entre servidores mediante pesos y añada servidores de respaldo que solo asuman el control cuando falle el grupo principal.
Balanceo de carga ponderado y servidores de respaldo es una lección gratuita de API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) en CoddyKit. Esta es la lección 4 de 4. Puedes leer la lección completa abajo gratuitamente — luego la practicas en el navegador con un editor de código integrado y un tutor de IA 24/7. Forma parte de la ruta de aprendizaje de API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway), y tu progreso se sincroniza en la web y la app de CoddyKit. El curso de API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) incluye 4 lecciones en total.
Partes de esta lección aún no han sido traducidas y se muestran en inglés.
When Servers Are Not Equal
Real upstream pools often mix machines of different capacity. A new 16-core server should not get the same share as an old 4-core box.
Nginx lets you bias traffic with weights so stronger servers handle more requests.
The weight Parameter
Add weight=N to a server. The default weight is 1. A server with weight=3 receives roughly three times as many requests as a weight=1 server.
upstream app {
server 10.0.0.1 weight=3;
server 10.0.0.2 weight=1;
}How the Ratio Works
With weights 3 and 1, out of every 4 requests, 3 go to the first server and 1 to the second. Weights are relative, so 6 and 2 produce the same split as 3 and 1.
Weights with Other Algorithms
Weights work with round robin (the default) and least connections. They do not apply to ip_hash, which selects a server purely from the client IP.
upstream app {
least_conn;
server 10.0.0.1 weight=5;
server 10.0.0.2 weight=2;
}Introducing Backup Servers
A server marked backup receives no traffic while any primary server is available. It activates only when all primaries are down or unreachable.
upstream app {
server 10.0.0.1;
server 10.0.0.2;
server 10.0.0.9 backup;
}Why Use a Backup
Backups give you a graceful fallback, for example a maintenance page server or a secondary data center, without sending it normal traffic during healthy operation.
Marking a Server Down
Use down to permanently remove a server from rotation, handy during planned maintenance without deleting the line.
upstream app {
server 10.0.0.1;
server 10.0.0.2 down;
}Failure Detection Parameters
max_fails sets how many failed attempts mark a server unavailable, and fail_timeout sets the window and how long it stays out.
server 10.0.0.1 max_fails=3 fail_timeout=30s;Combining Weight and Backup
You can mix weights for primaries and keep a single backup for the whole pool. The backup ignores weight until it is the only option.
upstream app {
server 10.0.0.1 weight=4;
server 10.0.0.2 weight=1;
server 10.0.0.9 backup;
}Limiting Connections
The max_conns parameter caps simultaneous connections to a server, protecting a weaker box even if its weight is high.
server 10.0.0.2 weight=2 max_conns=100;Testing the Distribution
Fire many requests and check your access logs per upstream to confirm the ratio matches the weights. Adjust weights based on observed CPU and latency.
for i in $(seq 1 100); do curl -s http://localhost/ > /dev/null; doneQuick Check
A server is marked backup. When does it receive requests?
Recap
You learned to fine-tune traffic distribution:
weight=Nbiases traffic toward stronger servers- Weights are relative and apply to round robin and least_conn
backupservers activate only when primaries faildown,max_fails, andmax_connscontrol availability
Together these give you precise control over an uneven server fleet.
Aprende API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) con un tutor de IA — gratis
Escribe y ejecuta código real en tu navegador, obtén ayuda instantánea de un tutor de IA disponible 24/7 y continúa donde lo dejaste en la web o en la aplicación.
- Cursos
- 12
- Lecciones
- 48
Preguntas frecuentes
¿La lección «Balanceo de carga ponderado y servidores de respaldo» es gratis?
Sí — el texto completo de «Balanceo de carga ponderado y servidores de respaldo» es gratis para leer aquí en la web. Para practicarla de forma interactiva (editor de código integrado y tutor de IA 24/7) y desbloquear el resto del curso de API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway), actualiza a CoddyKit PRO. El curso de API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) incluye 4 lecciones en total.
¿Qué aprenderé en «Balanceo de carga ponderado y servidores de respaldo»?
Distribuya el tráfico de forma desigual entre servidores mediante pesos y añada servidores de respaldo que solo asuman el control cuando falle el grupo principal. Practicas API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) con código real que ejecutas directamente en el navegador, y un tutor de IA 24/7 responde tus preguntas mientras trabajas en la lección.
¿Necesito experiencia previa para empezar API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway)?
No se requiere experiencia previa. API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) en CoddyKit está estructurado para principiantes hasta estudiantes avanzados, así que puedes empezar aquí o desde el inicio y avanzar a tu ritmo. Esta es la lección 4 de 4.
¿Cuánto tiempo toma la lección «Balanceo de carga ponderado y servidores de respaldo»?
La mayoría de las lecciones de CoddyKit toman alrededor de 5–10 minutos. Cada una es compacta e interactiva, así que avanzas constantemente y retomas exactamente por donde dejaste en la web y la app.
¿Puedo escribir y ejecutar código en esta lección de API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway)?
Sí. Cada lección de API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) incluye un editor de código integrado, así que escribes y ejecutas código real directamente en tu navegador y obtienes retroalimentación instantánea de IA — sin configuración local necesaria.
Todas las lecciones de este curso
- Algoritmos de balanceo de carga
- Comprobaciones de estado y supervisión de servidores
- Sesiones persistentes y afinidad de sesión
- Balanceo de carga ponderado y servidores de respaldo