HTTP 负载均衡
在 Web 或应用服务器组之间负载平衡 HTTP 流量,使用多种算法和高级功能,如慢启动和会话保持。
概述
跨多个应用程序实例进行负载平衡是一种常用的技术,用于优化资源利用率、最大化吞吐量、减少延迟,并确保容错配置。
观看 NGINX Plus for Load Balancing and Scaling 网络研讨会,深入了解 NGINX 用户用于构建大规模、高可用性 Web 服务的技术。
NGINX 和 NGINX Plus 可以在不同的部署场景中作为非常高效的 HTTP 负载均衡器使用。
代理 HTTP 流量到一组服务器
要开始使用 NGINX Plus 或 NGINX Open Source 将 HTTP 流量负载均衡到一组服务器,首先需要使用 upstream 指令定义该组。该指令位于 http 上下文中。
组中的服务器使用 server 指令进行配置(不要与定义在 NGINX 上运行的虚拟服务器的 server 块混淆)。
例如,以下配置定义了一个名为 backend 的组,由三个服务器配置组成(实际服务器可能超过三个):
http {
upstream backend {
server backend1.example.com weight=5;
server backend2.example.com;
server 192.0.0.1 backup;
}
}
为了将请求传递给服务器组,组的名称在 proxy_pass 指令中指定(或者对于这些协议,可以在 fastcgi_pass、memcached_pass、scgi_pass 或 uwsgi_pass 指令中指定)。
在下一个示例中,运行在 NGINX 上的虚拟服务器将所有请求传递给前面示例中定义的 backend 上游组:
server {
location / {
proxy_pass http://backend;
}
}
以下示例结合了上面的两个片段,并展示了如何将 HTTP 请求代理到后端服务器组。
该组由三个服务器组成,其中两个运行着相同应用程序的实例,而第三个是备份服务器。
由于在 upstream 块中未指定负载均衡算法,NGINX 使用默认算法,即 Round Robin:
http {
upstream backend {
server backend1.example.com;
server backend2.example.com;
server 192.0.0.1 backup;
}
server {
location / {
proxy_pass http://backend;
}
}
}
nginx 系列
Nginx-02-Nginx Ubuntu 安装 + windows10 + WSL ubuntu 安装 nginx 实战笔记
Nginx-05-nginx 反向代理是什么?windows 下如何配置使用 nginx
Nginx R31 doc 官方文档-01-nginx 如何安装
Nginx R31 doc-03-HTTP Load Balancing HTTP 负载均衡
Nginx R31 doc-04-HTTP Health Checks
Nginx R31 doc-06-Accepting the PROXY Protocol
Nginx R31 doc-08-Configuring NGINX and NGINX Plus as a Web Server 配置 NGINX 和 NGINX Plus 作为 Web 服务器
Nginx R31 doc-09-Serving Static Content 静态内容
Nginx R31 doc-10-NGINX Reverse Proxy 反向代理
Nginx R31 doc-11-Compression and Decompression 压缩与解压缩
Nginx R31 doc-12-NGINX SSL Termination 安全加密
Nginx R31 doc-13-Limiting Access to Proxied HTTP Resources 访问限流
Nginx R31 doc-14-Dynamic Denylisting of IP Addresses 动态拒绝IP地址
Nginx R31 doc-15-Live Activity Monitoring 实时活动监控
Nginx R31 doc-18-High Availability Support for NGINX Plus in On-Premises Deployments
Nginx 实战-01-nginx windows 安装笔记
Nginx 实战-02-nginx proxy_pass 服务代理访问 使用笔记 ubuntu nodejs
网友评论