Nginx Upstream模块

简介:

品茶:这是与大神JSBBA一块交流而录的视频,结果视频出问题了,不能正常,所以无法播放。看到老版后进入了新版页面,结果全是商业版的功能,不过有些东西理解好了


#nginx upstream

我是品茶 还有大神JSBBA 一起交流

负载均衡

硬件-F5

开源-{

lvs+keepalived

haproxy

nginx

}

nginx upstream


ups {

web1

web2

web3  标注为不可用

}

upstreamModule:

优点:iphash hash(remote_addr)

nginx hashmap{

"7675334710322792576":"web1"

}

1、

client1(100.2) > nginx -hash(remmote_addr) > web1

2、

client1(100.2) > nginx -hash(remmote_addr) > web1

3、

client2(200.3) > nginx -hash(remmote_addr) > web2

反向代理:

client >> 反向代理{

web1

web2

web3

} >>server


反向代理 接近服务器的

正向代理 接近客户端的也就是自己的

透明代理 客户端完全不知道有代理这个东西


proxy_pass ups;



upstream backend {

   server backend1.example.com       weight=5;

   server backend2.example.com:8080;

   server unix:/tmp/backend3;


   server backup1.example.com:8080   backup;

   server backup2.example.com:8080   backup;

}


http{

server{

localtion{

image_fillter_module

proxy_pass

}

}

}

server {

   location / {

       proxy_pass http://backend;

   }

}

说明:

syntax:upstream name { ... }

default: —

context:http


syntax:server address [parameters];

default: —

context:upstream

server parameters {

weight=number 1

masx_fails=number 1

fail_timeout=time 10

slow_start=time 0(商业版本才有的功能)

backup 备机

down 停用  (ip_hash)

route=string

}


syntax:match name { ... }

default: —

context:http



syntax:zone name size;

default: —

context:upstream

间隔 5   连续失败 1连续通过 1 url  /   检测状态

syntax:health_check [interval=time] [fails=number] [passes=number] [uri=uri] [match=name];

default: —

context:location


syntax:keepalive connections;

default: —

context:upstream

This directive appeared in version 1.1.4.




upstream appservers {

   zone appservers 64k;


   server appserv1.example.com      weight=5;

   server appserv2.example.com:8080 fail_timeout=5s slow_start=30s;

   server 192.0.2.1                 max_fails=3;


   server reserve1.example.com:8080 backup;

   server reserve2.example.com:8080 backup;

}


server {

   location / {

       proxy_pass http://appservers;

       health_check;

   }


   location /upstream_conf {

       upstream_conf;

       allow 127.0.0.1;

       deny all;

   }

}


check www.baidu.com 80

if status == "200"

   open 127.0.0.1/upstream_conf?upstream=ups&server=appserv1.example.com&weight=8

pass


NB:

http://127.0.0.1/upstream_conf?add=&upstream=appservers&server=127.0.0.1:8080&weight=2&max_fails=3&fail_timeout=3s&down=


任务:

upstream池两个,通过upstream_conf添加一个








check /

down


check /bbs

check /blog



location /bbs {

proxy_pass http://192.168.100.102;

}


location /blog {

proxy_pass http://192.168.100.103;

}

health_check   uri="/bbs" match=200


http://www.a.com/ ok

http://www.a.com/bbs not ok


keepalied 500 501连接的时候,

pool{

501

2

3

4}





本文转自 煮酒品茶 51CTO博客,原文链接:http://blog.51cto.com/cwtea/1343371,如需转载请自行联系原作者
目录
相关文章
|
1月前
|
应用服务中间件 nginx
Nginx安装nginx-rtmp-module模块
【2月更文挑战第4天】 nginx中的模块虽然就是类似插件的概念,但是它无法像VsCode那样轻松的安装扩展。 nginx要安装其它模块必须同时拿到nginx源代码和模块源代码,然后手动编译,将模块打到nginx中,最终生成一个名为nginx的可执行文件。
74 6
|
3月前
|
应用服务中间件 nginx
百度搜索:蓝易云【利用nginx内置ngx_http_mirror_module模块实现流量复制及流量放大】
以上就是使用Nginx内置 `ngx_http_mirror_module`模块实现流量复制和流量放大的简要示例。通过合理配置和利用该模块,可以实现更复杂的流量控制和调试需求。
58 1
|
5月前
|
负载均衡 算法 应用服务中间件
Nginx系列教程(08) - Upstream Server 负载均衡
Nginx系列教程(08) - Upstream Server 负载均衡
75 0
|
27天前
|
应用服务中间件 Linux PHP
Linux下安装php环境并且配置Nginx支持php-fpm模块
Linux下安装php环境并且配置Nginx支持php-fpm模块
29 0
|
2月前
|
消息中间件 关系型数据库 MySQL
使用Nginx的stream模块实现MySQL反向代理与RabbitMQ负载均衡
使用Nginx的stream模块实现MySQL反向代理与RabbitMQ负载均衡
63 0
|
3月前
|
存储 应用服务中间件 nginx
Nginx模块开发:handler模块实现
Nginx模块开发:handler模块实现
28 0
|
3月前
|
存储 应用服务中间件 nginx
Nginx模块开发:模块结构的源码阅读以及过滤器(Filter)模块的实现
Nginx模块开发:模块结构的源码阅读以及过滤器(Filter)模块的实现
65 0
|
3月前
|
存储 应用服务中间件 nginx
Nginx:过滤模块的实现
Nginx:过滤模块的实现
|
3月前
|
存储 负载均衡 网络协议
Nginx: handler 模块的实现
Nginx: handler 模块的实现
|
3月前
|
前端开发 应用服务中间件 nginx
nginx过滤器模块
nginx过滤器模块