nginx反向代理和负载均衡的区别
1、反向代理,不需要服务器池,直接代理某台服务器
location / {
proxy_pass http://192.168.18.201;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
}
proxy_set_header Host $host; nginx请求地址池时带着客户端请求的主机头
proxy_set_header X-Forwarded-For $remote_addr; 负载均衡器开启ip转发,将客户端ip映射到web服务器
2、负载均衡,后端有服务器池upstream
upstream webservers {
server 192.168.18.201 weight=1;
server 192.168.18.202 weight=1;
location / {
proxy_pass http://webservers;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
}