Nginx七层负载均衡
Nginx七层负载均衡
先利用ngx_http_upstream_module模块定义一个后端服务器组
在利用ngx_http_proxy_module模块中的 proxy_pass指令进行代理转发到定义的后端服务器组
ngx_http_upstream_module模块常用配置项可以参考这个文章
Nginx利用ngx_http_upstream_module模块定义后端服务器组
示例
环境:
后端服务器:
192.168.253.129 (提供了web服务)
192.168.253.139(提供了web服务)
代理服务器:
192.168.253.128
代理服务器的主配置文件
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
upstream backend { #定义后端服务器组
server 192.168.253.129 weight=2;
server 192.168.253.139 weight=5;
}
server {
listen 80;
server_name localhost;
location / {
proxy_pass http://backend; #将请求代理到backend这个后端服务器组中
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
还没有评论,来说两句吧...