标签:ip_hash htm 地址 serve web服务器 配置 name list 参数
1、ngx_http_upstream_module模块常用功能说明:
1)定义后端集群web节点信息,定义一个地址的池子
upstream oldboy {
server 10.0.0.7:80;
server 10.0.0.8:80;
server 10.0.0.9:80;
}
2)实现权重值负载访问功能
upstream oldboy {
server 10.0.0.7:80 weight=3;
server 10.0.0.8:80 weight=1;
server 10.0.0.9:80 weight=1;
}
3)定义后端访问的失败次数-max_fails
upstream oldboy {
server 10.0.0.7:80 weight=3 max_fails=3;
server 10.0.0.8:80 weight=1 max_fails=3;
server 10.0.0.9:80 weight=1 max_fails=3;
}
4)定义后端失败重试的间隔-fail_timeout
upstream oldboy {
server 10.0.0.7:80 weight=3 max_fails=3 fail_timeout=10s;
server 10.0.0.8:80 weight=1 max_fails=3;
server 10.0.0.9:80 weight=1 max_fails=3;
}
说明:在尝试多次失败后,在超时时间过去之后,会再给相应节点一次机会
5)定义后端服务的热备节点-backup
upstream oldboy {
server 10.0.0.7:80;
server 10.0.0.8:80;
server 10.0.0.9:80 backup;
}
模块常用调度算法:
1)定义轮询调度算法-rr-默认调度算法
采取平均分配
2)定义权重调度算法-wrr
能者多劳
3)定义静态调度算法-ip_hash
说明:配置ip_hash时,一定不能和backup与weight参数同时出现
upstream oldboy {
ip_hash;
server 10.0.0.7:80;
server 10.0.0.8:80;
server 10.0.0.9:80 backup;
}
4)定义最小的连接数-least_conn
upstream oldboy {
least_conn;
server 10.0.0.7:80;
server 10.0.0.8:80;
server 10.0.0.9:80 backup;
}
2、ngx_http_proxy_module
http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_pass
模块常用功能:
proxy_set_header --- 设置反向代理服务器到web服务器的HTTP请求报文中的头部信息
说明:通过该配置,可以实现访问负载均衡看到不同虚拟主机页面信息
server {
listen 80;
server_name www.etiantian.org;
root html;
index index.html index.htm;
location / {
proxy_pass http://oldboy;
proxy_set_header host $host;
}
}
server {
listen 80;
server_name bbs.etiantian.org;
proxy_set_header host $host;
root html;
index index.html index.htm;
location / {
proxy_pass http://oldboy;
proxy_set_header host $host;
}
}
说明:实现用户访问反向代理服务,让web服务器日志中记录真实用户IP地址信息
server {
listen 80;
server_name www.etiantian.org;
root html;
index index.html index.htm;
location / {
proxy_pass http://oldboy;
proxy_set_header host $host;
proxy_set_header X-Forwarded-For $remote_addr;
}
}
server {
listen 80;
server_name bbs.etiantian.org;
root html;
index index.html index.htm;
location / {
proxy_pass http://oldboy;
proxy_set_header X-Forwarded-For $remote_addr;
}
}
标签:ip_hash htm 地址 serve web服务器 配置 name list 参数
原文地址:https://blog.51cto.com/tangyong/2433750