nginx upstream 配置

upstream servers默认是rr队列,在server的最后面加上权重就自动成为wrr

(1)编辑nginx.conf 在http {}编辑upsteam

         upstream dynamic {

         server 11.100.46.7 weight=2;

         server 11.100.46.4;

         server 11.100.46.9;

         }

(2)编辑nginx.conf 在http {}编辑upsteam,在server的后面加上backup就成为了备份服务器了,不再转发。除非主用的全部下线。

         upstream dynamic {

         server 11.100.46.7 weight=2;

         server 11.100.46.4;

         server 11.100.46.9 backup;

         }

 

(3)编辑nginx.conf 在http {}编辑upsteam,在upsteam中加入ip_hash;就成了sh调度了

        注意不支持backupserver。

             upstream dynamic {

             ip_hash;

             server 11.100.46.7 weight=2;

             server 11.100.46.4;

             server 11.100.46.9;

             }

(4)编辑nginx.conf 在http {}编辑upsteam,在server的后面加上down,服务器就下线了。

        upstream dynamic {

         # ip_hash;

         server 11.100.46.7 weight=2;

         server 11.100.46.4 max_fails=3 fail_timeout=1s;

         server 11.100.46.9 down;

         }

(5)支持加权的最小连接,基于realserver繁忙程度进行调度。

    

        upstream dynamic {

         # ip_hash;

         least_conn;

         server 11.100.46.7 weight=2;

         server 11.100.46.4 max_fails=3 fail_timeout=1s;

         server 11.100.46.9 down;

         }

(6)keepalive与后端upstream server之间支持持久连接(非httpd才会使用非持久连接,memcached)

 

 

(7)health_check只能在商业版中使用。

         server {

         location / {

         proxy_pass http://dynamic;

         health_check;

         }

         第二种关闭日志

         http {

         server {

         …

         location / {

         proxy_pass http://backend;

         health_check match=welcome;

         }

         }

 

         match welcome {

         status 200;

         header Content-Type = text/html;

         body ~ “Welcome to nginx!”;

         }

        }

        

(8)sticky基于cookie商业版才能使用。

        upstream backend {

         server backend1.example.com;

         server backend2.example.com;

 

         sticky cookie srv_id expires=1h domain=.example.com path=/;

        }

 

(9)传递参数给浏览器在location / {}添加

        # vim server.conf

        add_header X-Via $upstream_addr;

         add_header X-Cache $upstream_cache_status;

更多推荐