nginx反向代理

  1. 语法格式
http{
    upstream webs{             //定义源服务器组,webs可以自定义
        web1 192.168.4.1:80;
        web2 192.168.4.2:80;
    }
    server{
        listen 80;
        server_name www.terena.com;
        location / {
        ....
            proxy_pass http://wesbs;   //调用源服务器组
        }
    }
}
  1. 调度算法
- 轮询(默认算法):逐一循环调度
- weight  加权轮询
- ip_hash 跟聚客户端ip分配固定的服务器,也就是slb中的会话保持功能
  1. 服务器组的状态
- down 表示该主机暂时不参与负载
- max_fails 允许请求失败的次数,默认为1
- fail_timeout max_fails次失败后,暂停提供服务的时间
- backup 备份服务器
upstream webs{
    #ip_hash
    web1 192.168.4.1:80 down;
    web2 192.168.4.2:80 weigth=2;
    web3 192.168.4.3:80 backup;
    web4 192.168.4.4:80 max_fails=2 fail_timeout=30;
}
  1. nginx四层调度tcp/udp
- 编译时要加--with-stream 
- 配置文件格式
    stream {
            upstream backend {
               server 192.168.2.100:22;            //后端SSH服务器的IP和端口
               server 192.168.2.200:22;
            }
            server {
                listen 12345;                    //Nginx监听的端口
                proxy_connect_timeout 1s;
                proxy_timeout 3s;
                proxy_pass backend;
             }
    }
http {
.. ..
}
posted @ 2020-01-02 14:24  昭昭木木  阅读(86)  评论(0编辑  收藏  举报