前言:centos7.4下nginx+两个centos容器(容器中搭建nginx+php环境)尝试搭建负载均衡
端口 宿主机:容器1 10000:80 宿主机:容器1 10001:80
容器内nginx的配置正常配置
宿主机的配置
# 此处的域名和下面location中的域名一样
upstream www.itryfirst.top { server 47.106.101.127:10000 weight=1; server 47.106.101.127:10001 weight=2; }
server {
listen 80;
server_name www.itryfirst.top;
location / {
proxy_pass http://www.itryfirst.top; # 代理域名自己配置
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
upstream还可以为每个设备设置状态值,这些状态值的含义分别如下:
down 表示单前的server暂时不参与负载.
weight 默认为1.weight越大,负载的权重就越大。
max_fails :允许请求失败的次数默认为1.当超过最大次数时,返回proxy_next_upstream 模块定义的错误.
fail_timeout : max_fails次失败后,暂停的时间。
backup: 其它所有的非backup机器down或者忙的时候,请求backup机器。所以这台机器压力会最轻。
ps:文章只是作为笔记使用,均是参考他人的