From 594c2857344f1058a404479fab4f732f96268f36 Mon Sep 17 00:00:00 2001 From: xtomrfx Date: Wed, 29 Sep 2021 22:55:56 +0800 Subject: [PATCH 01/23] test --- .../Web1/conf.d/default.conf" | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git "a/5 NGINX\346\225\217\346\215\267\351\205\215\347\275\256/Web1/conf.d/default.conf" "b/5 NGINX\346\225\217\346\215\267\351\205\215\347\275\256/Web1/conf.d/default.conf" index 0bf6325..f38cbb0 100644 --- "a/5 NGINX\346\225\217\346\215\267\351\205\215\347\275\256/Web1/conf.d/default.conf" +++ "b/5 NGINX\346\225\217\346\215\267\351\205\215\347\275\256/Web1/conf.d/default.conf" @@ -9,7 +9,7 @@ server { default_type application/json; return 200 '{"deadlocks":{"healthy":true},"Disk":{"healthy":true},"Memory":{"healthy":true}}'; } - + # test location / { #root /usr/share/nginx/html; #index index.html index.htm; -- Gitee From e7f7e3404d1183ad7127237de989b1a55cc9aba4 Mon Sep 17 00:00:00 2001 From: xtomrfx Date: Wed, 29 Sep 2021 22:58:41 +0800 Subject: [PATCH 02/23] test --- .../Web1/conf.d/default.conf" | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git "a/5 NGINX\346\225\217\346\215\267\351\205\215\347\275\256/Web1/conf.d/default.conf" "b/5 NGINX\346\225\217\346\215\267\351\205\215\347\275\256/Web1/conf.d/default.conf" index f38cbb0..2c07b1d 100644 --- "a/5 NGINX\346\225\217\346\215\267\351\205\215\347\275\256/Web1/conf.d/default.conf" +++ "b/5 NGINX\346\225\217\346\215\267\351\205\215\347\275\256/Web1/conf.d/default.conf" @@ -9,7 +9,7 @@ server { default_type application/json; return 200 '{"deadlocks":{"healthy":true},"Disk":{"healthy":true},"Memory":{"healthy":true}}'; } - # test + # test123 location / { #root /usr/share/nginx/html; #index index.html index.htm; -- Gitee From f92e07ed5b1e39196e2f0f6eea4a240684fa21bf Mon Sep 17 00:00:00 2001 From: xtomrfx Date: Wed, 29 Sep 2021 23:01:19 +0800 Subject: [PATCH 03/23] commit --- .../Web1/conf.d/default.conf" | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git "a/5 NGINX\346\225\217\346\215\267\351\205\215\347\275\256/Web1/conf.d/default.conf" "b/5 NGINX\346\225\217\346\215\267\351\205\215\347\275\256/Web1/conf.d/default.conf" index 2c07b1d..707dccf 100644 --- "a/5 NGINX\346\225\217\346\215\267\351\205\215\347\275\256/Web1/conf.d/default.conf" +++ "b/5 NGINX\346\225\217\346\215\267\351\205\215\347\275\256/Web1/conf.d/default.conf" @@ -9,7 +9,7 @@ server { default_type application/json; return 200 '{"deadlocks":{"healthy":true},"Disk":{"healthy":true},"Memory":{"healthy":true}}'; } - # test123 + location / { #root /usr/share/nginx/html; #index index.html index.htm; -- Gitee From 19f596ff770c74659fa5994b41b0de53309bf2a1 Mon Sep 17 00:00:00 2001 From: xtomrfx Date: Wed, 29 Sep 2021 23:11:39 +0800 Subject: [PATCH 04/23] commit --- .../lab1_implicit_flow_gcp/README.md" | 168 ++++++++++++++++++ .../lab2_author_code_flow_okta/README.md" | 168 ++++++++++++++++++ .../lab3_token_introspection_okta/README.md" | 168 ++++++++++++++++++ 3 files changed, 504 insertions(+) create mode 100644 "10 NGINX\350\256\244\350\257\201\346\216\210\346\235\203/lab1_implicit_flow_gcp/README.md" create mode 100644 "10 NGINX\350\256\244\350\257\201\346\216\210\346\235\203/lab2_author_code_flow_okta/README.md" create mode 100644 "10 NGINX\350\256\244\350\257\201\346\216\210\346\235\203/lab3_token_introspection_okta/README.md" diff --git "a/10 NGINX\350\256\244\350\257\201\346\216\210\346\235\203/lab1_implicit_flow_gcp/README.md" "b/10 NGINX\350\256\244\350\257\201\346\216\210\346\235\203/lab1_implicit_flow_gcp/README.md" new file mode 100644 index 0000000..5484746 --- /dev/null +++ "b/10 NGINX\350\256\244\350\257\201\346\216\210\346\235\203/lab1_implicit_flow_gcp/README.md" @@ -0,0 +1,168 @@ +# Lab环境介绍 + +本次演示和实验采用Docker环境,学员可根据自己实际情况准备实验环境。本环境中包含以下组件: + +## NGINX Plus反向代理服务器 +后面简称反代,可通过*Dockerfile*生成容器镜像,容器暴露端口如下: +- Web服务:8080:80 +- API:8000:8000 + +容器启动后,登录容器,在/etc/nginx/conf.d/目录下创建 *api-8000.conf* ,执行 `nginx -s reload` ,在实验客户端访问 http://x.x.x.x:8080 确认可以看到NGINX欢迎页面,访问 http://x.x.x.x:8000 ,确认可以打开Dashboard。x.x.x.x为Docker服务器的IP,也即反代的IP,下同。 + +## Web Servers +后面简称Web,可直接使用和反代相同的N+镜像,不对外暴露端口,使用Docker网桥和N+反代通信 + +## 测试客户端 +请预装以下软件,并且为了方便测试,建议在客户端hosts配置测试所用域名。 +- curl +- wrk +- 浏览器 + +--- + +# 实验步骤 + +NGINX安装目录为/etc/nginx/,所有实验配置文件均保存在/etc/nginx/conf.d/目录下。 + +请修改实验客户端*hosts*文件,将实验相关域名解析到反代的IP,反代IP设定为x.x.x.x。 + +## Lab1 变量 +1. 在反代中创建 *variable.conf* 文件,执行 `nginx -s reload` ,观察配置文件是否能被加载。 + +2. 访问http://variable.will.com:8080/noset 和 http://variable.will.com:8080/set ,观察返回的页面信息。 + +3. 删除 *variable.conf* 中第4行的注释符 + ``` + set $f5 "is the best ADC!"; + ``` + 重复第1、2步。 + +4. 在 *variable.conf* 中第11行增加注释符 + ``` + #set $f5 "NGINX is a part of F5"; + ``` + 重复第1步。 + +## Lab2 蓝绿部署 +1. 在反代中创建 *bluegreen.conf* 文件,upstream *blue* 和 *green* 分别修改为Web1和Web2的容器IP,执行 `nginx -s reload`。 +2. 在实验客户端执行以下命令,观察输出,应该为空。 + ``` + curl http://x.x.x.x:8000/api/6/http/keyvals/blue-green + ``` +3. 访问 http://bluegreen.will.com:8080 ,应该访问到Web1。 +4. 在实验客户端执行以下命令。 + ``` + curl -X POST -d '{"environment": "green"} http://x.x.x.x:8000/api/6/http/keyvals/blue-green + ``` +5. 访问 http://bluegreen.will.com:8080 ,应该访问到Web2。 +6. 在实验客户端执行以下命令。 + ``` + curl -X PATCH -d '{"environment": "blue"} http://x.x.x.x:8000/api/6/http/keyvals/blue-green + ``` +7. 访问 http://bluegreen.will.com:8080 ,应该访问到Web1。 + +## Lab3 AB Test +1. 在反代中创建 *abtest.conf* 文件,upstream *abtest_a* 和 *abtest_b* 分别修改为Web1和Web2的容器IP,执行 `nginx -s reload`。 +2. 在实验客户端通过wrk打压力,参考命令 `wrk -c200 -t8 -d300s "http://abtest.will.com:8080" ,打开Dashboard,观察upstream,所有的request应该都打向abtest_a。 +3. 在实验客户端执行以下命令。 + ``` + curl -X POST -d '{"bpercentage": 5} http://x.x.x.x:8000/api/6/http/keyvals/abtest + ``` +4. 通过Dashboard,观察upstream,应该有5%左右的request打向abtest_b。 +5. 在实验客户端执行以下命令。 + ``` + curl -X PATCH -d '{"bpercentage": 20} http://x.x.x.x:8000/api/6/http/keyvals/abtest + ``` +6. 通过Dashboard,观察upstream,应该有20%左右的request打向abtest_b。 +7. 在实验客户端执行以下命令。 + ``` + curl -X PATCH -d '{"bpercentage": 50} http://x.x.x.x:8000/api/6/http/keyvals/abtest + ``` +8. 通过Dashboard,观察upstream,应该有50%左右的request打向abtest_b。 +9. 在实验客户端执行以下命令。 + ``` + curl -X PATCH -d '{"bpercentage": 100} http://x.x.x.x:8000/api/6/http/keyvals/abtest + ``` +10. 通过Dashboard,观察upstream,应该所有的request都打向abtest_b。 + +## Lab4 灰度发布 +1. 在反代中创建 *canary.conf* 文件,upstream *v1_only* 、 *v2_only* 、 *all* 分别修改为Web1和Web2的容器IP,执行 `nginx -s reload`。 +2. 在实验客户端多次用curl模拟各种浏览器访问,应该在Web1和Web2之间轮询。 + ``` + curl -A 'Chrome' http://canary.will.com:8080 + ``` +3. 在实验客户端执行以下命令。 + ``` + curl -X POST -d '{"stage": "b"} http://x.x.x.x:8000/api/6/http/keyvals/canary + ``` +4. 在实验客户端多次用curl模拟各种浏览器访问,应该只会访问到Web1。 + ``` + curl -A 'Chrome' http://canary.will.com:8080 + ``` +5. 在实验客户端执行以下命令。 + ``` + curl -X PATCH -d '{"stage": "c"} http://x.x.x.x:8000/api/6/http/keyvals/canary + ``` +6. 在实验客户端多次用curl模拟Chrome浏览器访问,应该只会访问到Web2。 + ``` + curl -A 'Chrome' http://canary.will.com:8080 + ``` +7. 在实验客户端多次用curl模拟Firefox浏览器访问,应该只会访问到Web1。 + ``` + curl -A 'Firefox' http://canary.will.com:8080 + ``` +8. 在实验客户端模拟其它浏览器访问,例如Safari,应该也只会访问到Web1。 +9. 在实验客户端执行以下命令。 + ``` + curl -X PATCH -d '{"stage": "d"} http://x.x.x.x:8000/api/6/http/keyvals/canary + ``` +10. 在实验客户端多次用curl模拟各种浏览器访问,应该只会访问到Web2。 +11. 在实验客户端执行以下命令。 + ``` + curl -X PATCH -d '{"stage": "a"} http://x.x.x.x:8000/api/6/http/keyvals/canary + ``` +12. 在实验客户端多次用curl模拟各种浏览器访问,应该在Web1和Web2之间轮询。 + +## Lab5 动态限流 +1. 在反代中创建 *ratelimit.conf* 文件,upstream *ratelimit* 分别修改为Web1和Web2的容器IP,执行 `nginx -s reload`。 +2. 在实验客户端通过wrk打压力,参考命令 `wrk -c200 -t8 -d300s "http://ratelimit.will.com:8080" ,打开Dashboard观察,此时应该是正常分发流量,没有任何限速。 +3. 在实验客户端执行以下命令,打开限速200rps的开关。 + ``` + curl -X POST -d '{"ratelimit_200": 1} http://x.x.x.x:8000/api/6/http/keyvals/kv_ratelimit + ``` +4. 打压力的同时观察Dashboard,应该被限制在了200rps左右,同时观察delay的效果。 +5. 在实验客户端执行以下命令,打开限速100rps的开关。 + ``` + curl -X POST -d '{"ratelimit_100": 1} http://x.x.x.x:8000/api/6/http/keyvals/kv_ratelimit + ``` +6. 打压力的同时观察Dashboard,应该被限制在了100rps左右,同时观察nodelay的效果。 + +## Lab6 熔断 +1. 在反代中创建 *circuitbreaker.conf* 文件,upstream *circuitbreaker* 分别修改为Web1和Web2的容器IP,执行 `nginx -s reload`。 +2. 打开Dashboard,观察健康检查的情况。 +3. 在实验客户端通过wrk打压力,参考命令 `wrk -c200 -t8 -d300s "http://circuit.will.com:8080" ,打开Dashboard观察,此时应该是正常分发流量。 +4. 登录Web2容器,修改 */etc/nginx/conf.d/default.conf* 文件,将以下部分中return的值做任意改变,执行 `nginx -s reload`。 + ``` + location /health { + default_type application/json; + return 200 '{"deadlocks":{"healthy":true},"Disk":{"healthy":false},"Memory":{"healthy":true}}'; + } + ``` +5. 观察Dashboard,Web2应该被健康检查标记为down,流量全部打向Web1。 +6. 登录Web2容器,将 */etc/nginx/conf.d/default.conf* 文件修改为正常值,执行 `nginx -s reload`。 + ``` + location /health { + default_type application/json; + return 200 '{"deadlocks":{"healthy":true},"Disk":{"healthy":true},"Memory":{"healthy":true}}'; + } + ``` +7. 观察Dashboard,Web2连续三次健康检查通过后应该被重新标记为up,并且开始逐步接收流量,最终和Web1达到1:1。 +8. 删除反代 *circuitbreaker.conf* 文件中的slow_start参数,执行 `nginx -s reload`。 + ``` + upstream circuitbreaker { + server 172.17.0.3:80; + server 172.17.0.4:80; + zone circuitbreaker 64k; + } + ``` +9. 重复4至7步,观察没有slow_start时候的效果。 diff --git "a/10 NGINX\350\256\244\350\257\201\346\216\210\346\235\203/lab2_author_code_flow_okta/README.md" "b/10 NGINX\350\256\244\350\257\201\346\216\210\346\235\203/lab2_author_code_flow_okta/README.md" new file mode 100644 index 0000000..5484746 --- /dev/null +++ "b/10 NGINX\350\256\244\350\257\201\346\216\210\346\235\203/lab2_author_code_flow_okta/README.md" @@ -0,0 +1,168 @@ +# Lab环境介绍 + +本次演示和实验采用Docker环境,学员可根据自己实际情况准备实验环境。本环境中包含以下组件: + +## NGINX Plus反向代理服务器 +后面简称反代,可通过*Dockerfile*生成容器镜像,容器暴露端口如下: +- Web服务:8080:80 +- API:8000:8000 + +容器启动后,登录容器,在/etc/nginx/conf.d/目录下创建 *api-8000.conf* ,执行 `nginx -s reload` ,在实验客户端访问 http://x.x.x.x:8080 确认可以看到NGINX欢迎页面,访问 http://x.x.x.x:8000 ,确认可以打开Dashboard。x.x.x.x为Docker服务器的IP,也即反代的IP,下同。 + +## Web Servers +后面简称Web,可直接使用和反代相同的N+镜像,不对外暴露端口,使用Docker网桥和N+反代通信 + +## 测试客户端 +请预装以下软件,并且为了方便测试,建议在客户端hosts配置测试所用域名。 +- curl +- wrk +- 浏览器 + +--- + +# 实验步骤 + +NGINX安装目录为/etc/nginx/,所有实验配置文件均保存在/etc/nginx/conf.d/目录下。 + +请修改实验客户端*hosts*文件,将实验相关域名解析到反代的IP,反代IP设定为x.x.x.x。 + +## Lab1 变量 +1. 在反代中创建 *variable.conf* 文件,执行 `nginx -s reload` ,观察配置文件是否能被加载。 + +2. 访问http://variable.will.com:8080/noset 和 http://variable.will.com:8080/set ,观察返回的页面信息。 + +3. 删除 *variable.conf* 中第4行的注释符 + ``` + set $f5 "is the best ADC!"; + ``` + 重复第1、2步。 + +4. 在 *variable.conf* 中第11行增加注释符 + ``` + #set $f5 "NGINX is a part of F5"; + ``` + 重复第1步。 + +## Lab2 蓝绿部署 +1. 在反代中创建 *bluegreen.conf* 文件,upstream *blue* 和 *green* 分别修改为Web1和Web2的容器IP,执行 `nginx -s reload`。 +2. 在实验客户端执行以下命令,观察输出,应该为空。 + ``` + curl http://x.x.x.x:8000/api/6/http/keyvals/blue-green + ``` +3. 访问 http://bluegreen.will.com:8080 ,应该访问到Web1。 +4. 在实验客户端执行以下命令。 + ``` + curl -X POST -d '{"environment": "green"} http://x.x.x.x:8000/api/6/http/keyvals/blue-green + ``` +5. 访问 http://bluegreen.will.com:8080 ,应该访问到Web2。 +6. 在实验客户端执行以下命令。 + ``` + curl -X PATCH -d '{"environment": "blue"} http://x.x.x.x:8000/api/6/http/keyvals/blue-green + ``` +7. 访问 http://bluegreen.will.com:8080 ,应该访问到Web1。 + +## Lab3 AB Test +1. 在反代中创建 *abtest.conf* 文件,upstream *abtest_a* 和 *abtest_b* 分别修改为Web1和Web2的容器IP,执行 `nginx -s reload`。 +2. 在实验客户端通过wrk打压力,参考命令 `wrk -c200 -t8 -d300s "http://abtest.will.com:8080" ,打开Dashboard,观察upstream,所有的request应该都打向abtest_a。 +3. 在实验客户端执行以下命令。 + ``` + curl -X POST -d '{"bpercentage": 5} http://x.x.x.x:8000/api/6/http/keyvals/abtest + ``` +4. 通过Dashboard,观察upstream,应该有5%左右的request打向abtest_b。 +5. 在实验客户端执行以下命令。 + ``` + curl -X PATCH -d '{"bpercentage": 20} http://x.x.x.x:8000/api/6/http/keyvals/abtest + ``` +6. 通过Dashboard,观察upstream,应该有20%左右的request打向abtest_b。 +7. 在实验客户端执行以下命令。 + ``` + curl -X PATCH -d '{"bpercentage": 50} http://x.x.x.x:8000/api/6/http/keyvals/abtest + ``` +8. 通过Dashboard,观察upstream,应该有50%左右的request打向abtest_b。 +9. 在实验客户端执行以下命令。 + ``` + curl -X PATCH -d '{"bpercentage": 100} http://x.x.x.x:8000/api/6/http/keyvals/abtest + ``` +10. 通过Dashboard,观察upstream,应该所有的request都打向abtest_b。 + +## Lab4 灰度发布 +1. 在反代中创建 *canary.conf* 文件,upstream *v1_only* 、 *v2_only* 、 *all* 分别修改为Web1和Web2的容器IP,执行 `nginx -s reload`。 +2. 在实验客户端多次用curl模拟各种浏览器访问,应该在Web1和Web2之间轮询。 + ``` + curl -A 'Chrome' http://canary.will.com:8080 + ``` +3. 在实验客户端执行以下命令。 + ``` + curl -X POST -d '{"stage": "b"} http://x.x.x.x:8000/api/6/http/keyvals/canary + ``` +4. 在实验客户端多次用curl模拟各种浏览器访问,应该只会访问到Web1。 + ``` + curl -A 'Chrome' http://canary.will.com:8080 + ``` +5. 在实验客户端执行以下命令。 + ``` + curl -X PATCH -d '{"stage": "c"} http://x.x.x.x:8000/api/6/http/keyvals/canary + ``` +6. 在实验客户端多次用curl模拟Chrome浏览器访问,应该只会访问到Web2。 + ``` + curl -A 'Chrome' http://canary.will.com:8080 + ``` +7. 在实验客户端多次用curl模拟Firefox浏览器访问,应该只会访问到Web1。 + ``` + curl -A 'Firefox' http://canary.will.com:8080 + ``` +8. 在实验客户端模拟其它浏览器访问,例如Safari,应该也只会访问到Web1。 +9. 在实验客户端执行以下命令。 + ``` + curl -X PATCH -d '{"stage": "d"} http://x.x.x.x:8000/api/6/http/keyvals/canary + ``` +10. 在实验客户端多次用curl模拟各种浏览器访问,应该只会访问到Web2。 +11. 在实验客户端执行以下命令。 + ``` + curl -X PATCH -d '{"stage": "a"} http://x.x.x.x:8000/api/6/http/keyvals/canary + ``` +12. 在实验客户端多次用curl模拟各种浏览器访问,应该在Web1和Web2之间轮询。 + +## Lab5 动态限流 +1. 在反代中创建 *ratelimit.conf* 文件,upstream *ratelimit* 分别修改为Web1和Web2的容器IP,执行 `nginx -s reload`。 +2. 在实验客户端通过wrk打压力,参考命令 `wrk -c200 -t8 -d300s "http://ratelimit.will.com:8080" ,打开Dashboard观察,此时应该是正常分发流量,没有任何限速。 +3. 在实验客户端执行以下命令,打开限速200rps的开关。 + ``` + curl -X POST -d '{"ratelimit_200": 1} http://x.x.x.x:8000/api/6/http/keyvals/kv_ratelimit + ``` +4. 打压力的同时观察Dashboard,应该被限制在了200rps左右,同时观察delay的效果。 +5. 在实验客户端执行以下命令,打开限速100rps的开关。 + ``` + curl -X POST -d '{"ratelimit_100": 1} http://x.x.x.x:8000/api/6/http/keyvals/kv_ratelimit + ``` +6. 打压力的同时观察Dashboard,应该被限制在了100rps左右,同时观察nodelay的效果。 + +## Lab6 熔断 +1. 在反代中创建 *circuitbreaker.conf* 文件,upstream *circuitbreaker* 分别修改为Web1和Web2的容器IP,执行 `nginx -s reload`。 +2. 打开Dashboard,观察健康检查的情况。 +3. 在实验客户端通过wrk打压力,参考命令 `wrk -c200 -t8 -d300s "http://circuit.will.com:8080" ,打开Dashboard观察,此时应该是正常分发流量。 +4. 登录Web2容器,修改 */etc/nginx/conf.d/default.conf* 文件,将以下部分中return的值做任意改变,执行 `nginx -s reload`。 + ``` + location /health { + default_type application/json; + return 200 '{"deadlocks":{"healthy":true},"Disk":{"healthy":false},"Memory":{"healthy":true}}'; + } + ``` +5. 观察Dashboard,Web2应该被健康检查标记为down,流量全部打向Web1。 +6. 登录Web2容器,将 */etc/nginx/conf.d/default.conf* 文件修改为正常值,执行 `nginx -s reload`。 + ``` + location /health { + default_type application/json; + return 200 '{"deadlocks":{"healthy":true},"Disk":{"healthy":true},"Memory":{"healthy":true}}'; + } + ``` +7. 观察Dashboard,Web2连续三次健康检查通过后应该被重新标记为up,并且开始逐步接收流量,最终和Web1达到1:1。 +8. 删除反代 *circuitbreaker.conf* 文件中的slow_start参数,执行 `nginx -s reload`。 + ``` + upstream circuitbreaker { + server 172.17.0.3:80; + server 172.17.0.4:80; + zone circuitbreaker 64k; + } + ``` +9. 重复4至7步,观察没有slow_start时候的效果。 diff --git "a/10 NGINX\350\256\244\350\257\201\346\216\210\346\235\203/lab3_token_introspection_okta/README.md" "b/10 NGINX\350\256\244\350\257\201\346\216\210\346\235\203/lab3_token_introspection_okta/README.md" new file mode 100644 index 0000000..5484746 --- /dev/null +++ "b/10 NGINX\350\256\244\350\257\201\346\216\210\346\235\203/lab3_token_introspection_okta/README.md" @@ -0,0 +1,168 @@ +# Lab环境介绍 + +本次演示和实验采用Docker环境,学员可根据自己实际情况准备实验环境。本环境中包含以下组件: + +## NGINX Plus反向代理服务器 +后面简称反代,可通过*Dockerfile*生成容器镜像,容器暴露端口如下: +- Web服务:8080:80 +- API:8000:8000 + +容器启动后,登录容器,在/etc/nginx/conf.d/目录下创建 *api-8000.conf* ,执行 `nginx -s reload` ,在实验客户端访问 http://x.x.x.x:8080 确认可以看到NGINX欢迎页面,访问 http://x.x.x.x:8000 ,确认可以打开Dashboard。x.x.x.x为Docker服务器的IP,也即反代的IP,下同。 + +## Web Servers +后面简称Web,可直接使用和反代相同的N+镜像,不对外暴露端口,使用Docker网桥和N+反代通信 + +## 测试客户端 +请预装以下软件,并且为了方便测试,建议在客户端hosts配置测试所用域名。 +- curl +- wrk +- 浏览器 + +--- + +# 实验步骤 + +NGINX安装目录为/etc/nginx/,所有实验配置文件均保存在/etc/nginx/conf.d/目录下。 + +请修改实验客户端*hosts*文件,将实验相关域名解析到反代的IP,反代IP设定为x.x.x.x。 + +## Lab1 变量 +1. 在反代中创建 *variable.conf* 文件,执行 `nginx -s reload` ,观察配置文件是否能被加载。 + +2. 访问http://variable.will.com:8080/noset 和 http://variable.will.com:8080/set ,观察返回的页面信息。 + +3. 删除 *variable.conf* 中第4行的注释符 + ``` + set $f5 "is the best ADC!"; + ``` + 重复第1、2步。 + +4. 在 *variable.conf* 中第11行增加注释符 + ``` + #set $f5 "NGINX is a part of F5"; + ``` + 重复第1步。 + +## Lab2 蓝绿部署 +1. 在反代中创建 *bluegreen.conf* 文件,upstream *blue* 和 *green* 分别修改为Web1和Web2的容器IP,执行 `nginx -s reload`。 +2. 在实验客户端执行以下命令,观察输出,应该为空。 + ``` + curl http://x.x.x.x:8000/api/6/http/keyvals/blue-green + ``` +3. 访问 http://bluegreen.will.com:8080 ,应该访问到Web1。 +4. 在实验客户端执行以下命令。 + ``` + curl -X POST -d '{"environment": "green"} http://x.x.x.x:8000/api/6/http/keyvals/blue-green + ``` +5. 访问 http://bluegreen.will.com:8080 ,应该访问到Web2。 +6. 在实验客户端执行以下命令。 + ``` + curl -X PATCH -d '{"environment": "blue"} http://x.x.x.x:8000/api/6/http/keyvals/blue-green + ``` +7. 访问 http://bluegreen.will.com:8080 ,应该访问到Web1。 + +## Lab3 AB Test +1. 在反代中创建 *abtest.conf* 文件,upstream *abtest_a* 和 *abtest_b* 分别修改为Web1和Web2的容器IP,执行 `nginx -s reload`。 +2. 在实验客户端通过wrk打压力,参考命令 `wrk -c200 -t8 -d300s "http://abtest.will.com:8080" ,打开Dashboard,观察upstream,所有的request应该都打向abtest_a。 +3. 在实验客户端执行以下命令。 + ``` + curl -X POST -d '{"bpercentage": 5} http://x.x.x.x:8000/api/6/http/keyvals/abtest + ``` +4. 通过Dashboard,观察upstream,应该有5%左右的request打向abtest_b。 +5. 在实验客户端执行以下命令。 + ``` + curl -X PATCH -d '{"bpercentage": 20} http://x.x.x.x:8000/api/6/http/keyvals/abtest + ``` +6. 通过Dashboard,观察upstream,应该有20%左右的request打向abtest_b。 +7. 在实验客户端执行以下命令。 + ``` + curl -X PATCH -d '{"bpercentage": 50} http://x.x.x.x:8000/api/6/http/keyvals/abtest + ``` +8. 通过Dashboard,观察upstream,应该有50%左右的request打向abtest_b。 +9. 在实验客户端执行以下命令。 + ``` + curl -X PATCH -d '{"bpercentage": 100} http://x.x.x.x:8000/api/6/http/keyvals/abtest + ``` +10. 通过Dashboard,观察upstream,应该所有的request都打向abtest_b。 + +## Lab4 灰度发布 +1. 在反代中创建 *canary.conf* 文件,upstream *v1_only* 、 *v2_only* 、 *all* 分别修改为Web1和Web2的容器IP,执行 `nginx -s reload`。 +2. 在实验客户端多次用curl模拟各种浏览器访问,应该在Web1和Web2之间轮询。 + ``` + curl -A 'Chrome' http://canary.will.com:8080 + ``` +3. 在实验客户端执行以下命令。 + ``` + curl -X POST -d '{"stage": "b"} http://x.x.x.x:8000/api/6/http/keyvals/canary + ``` +4. 在实验客户端多次用curl模拟各种浏览器访问,应该只会访问到Web1。 + ``` + curl -A 'Chrome' http://canary.will.com:8080 + ``` +5. 在实验客户端执行以下命令。 + ``` + curl -X PATCH -d '{"stage": "c"} http://x.x.x.x:8000/api/6/http/keyvals/canary + ``` +6. 在实验客户端多次用curl模拟Chrome浏览器访问,应该只会访问到Web2。 + ``` + curl -A 'Chrome' http://canary.will.com:8080 + ``` +7. 在实验客户端多次用curl模拟Firefox浏览器访问,应该只会访问到Web1。 + ``` + curl -A 'Firefox' http://canary.will.com:8080 + ``` +8. 在实验客户端模拟其它浏览器访问,例如Safari,应该也只会访问到Web1。 +9. 在实验客户端执行以下命令。 + ``` + curl -X PATCH -d '{"stage": "d"} http://x.x.x.x:8000/api/6/http/keyvals/canary + ``` +10. 在实验客户端多次用curl模拟各种浏览器访问,应该只会访问到Web2。 +11. 在实验客户端执行以下命令。 + ``` + curl -X PATCH -d '{"stage": "a"} http://x.x.x.x:8000/api/6/http/keyvals/canary + ``` +12. 在实验客户端多次用curl模拟各种浏览器访问,应该在Web1和Web2之间轮询。 + +## Lab5 动态限流 +1. 在反代中创建 *ratelimit.conf* 文件,upstream *ratelimit* 分别修改为Web1和Web2的容器IP,执行 `nginx -s reload`。 +2. 在实验客户端通过wrk打压力,参考命令 `wrk -c200 -t8 -d300s "http://ratelimit.will.com:8080" ,打开Dashboard观察,此时应该是正常分发流量,没有任何限速。 +3. 在实验客户端执行以下命令,打开限速200rps的开关。 + ``` + curl -X POST -d '{"ratelimit_200": 1} http://x.x.x.x:8000/api/6/http/keyvals/kv_ratelimit + ``` +4. 打压力的同时观察Dashboard,应该被限制在了200rps左右,同时观察delay的效果。 +5. 在实验客户端执行以下命令,打开限速100rps的开关。 + ``` + curl -X POST -d '{"ratelimit_100": 1} http://x.x.x.x:8000/api/6/http/keyvals/kv_ratelimit + ``` +6. 打压力的同时观察Dashboard,应该被限制在了100rps左右,同时观察nodelay的效果。 + +## Lab6 熔断 +1. 在反代中创建 *circuitbreaker.conf* 文件,upstream *circuitbreaker* 分别修改为Web1和Web2的容器IP,执行 `nginx -s reload`。 +2. 打开Dashboard,观察健康检查的情况。 +3. 在实验客户端通过wrk打压力,参考命令 `wrk -c200 -t8 -d300s "http://circuit.will.com:8080" ,打开Dashboard观察,此时应该是正常分发流量。 +4. 登录Web2容器,修改 */etc/nginx/conf.d/default.conf* 文件,将以下部分中return的值做任意改变,执行 `nginx -s reload`。 + ``` + location /health { + default_type application/json; + return 200 '{"deadlocks":{"healthy":true},"Disk":{"healthy":false},"Memory":{"healthy":true}}'; + } + ``` +5. 观察Dashboard,Web2应该被健康检查标记为down,流量全部打向Web1。 +6. 登录Web2容器,将 */etc/nginx/conf.d/default.conf* 文件修改为正常值,执行 `nginx -s reload`。 + ``` + location /health { + default_type application/json; + return 200 '{"deadlocks":{"healthy":true},"Disk":{"healthy":true},"Memory":{"healthy":true}}'; + } + ``` +7. 观察Dashboard,Web2连续三次健康检查通过后应该被重新标记为up,并且开始逐步接收流量,最终和Web1达到1:1。 +8. 删除反代 *circuitbreaker.conf* 文件中的slow_start参数,执行 `nginx -s reload`。 + ``` + upstream circuitbreaker { + server 172.17.0.3:80; + server 172.17.0.4:80; + zone circuitbreaker 64k; + } + ``` +9. 重复4至7步,观察没有slow_start时候的效果。 -- Gitee From 23d51d1aceb4e87e47db321df6a9766611c9e3df Mon Sep 17 00:00:00 2001 From: xtomrfx Date: Thu, 30 Sep 2021 10:39:43 +0800 Subject: [PATCH 05/23] 1 --- .../lab1_implicit_flow_gcp/nginx.conf" | 58 +++++++ .../www/public_html/index.html" | 37 +++++ .../www/public_html/js.cookie.js" | 151 ++++++++++++++++++ .../www/public_html/private/index.html" | 13 ++ .../www/public_html/private/npic.png" | Bin 0 -> 2478 bytes 5 files changed, 259 insertions(+) create mode 100644 "10 NGINX\350\256\244\350\257\201\346\216\210\346\235\203/lab1_implicit_flow_gcp/nginx.conf" create mode 100644 "10 NGINX\350\256\244\350\257\201\346\216\210\346\235\203/lab1_implicit_flow_gcp/www/public_html/index.html" create mode 100644 "10 NGINX\350\256\244\350\257\201\346\216\210\346\235\203/lab1_implicit_flow_gcp/www/public_html/js.cookie.js" create mode 100644 "10 NGINX\350\256\244\350\257\201\346\216\210\346\235\203/lab1_implicit_flow_gcp/www/public_html/private/index.html" create mode 100644 "10 NGINX\350\256\244\350\257\201\346\216\210\346\235\203/lab1_implicit_flow_gcp/www/public_html/private/npic.png" diff --git "a/10 NGINX\350\256\244\350\257\201\346\216\210\346\235\203/lab1_implicit_flow_gcp/nginx.conf" "b/10 NGINX\350\256\244\350\257\201\346\216\210\346\235\203/lab1_implicit_flow_gcp/nginx.conf" new file mode 100644 index 0000000..125b713 --- /dev/null +++ "b/10 NGINX\350\256\244\350\257\201\346\216\210\346\235\203/lab1_implicit_flow_gcp/nginx.conf" @@ -0,0 +1,58 @@ + +user nginx; +worker_processes auto; + +error_log /var/log/nginx/error.log notice; +pid /var/run/nginx.pid; + + +events { + worker_connections 1024; +} + + +http { + include /etc/nginx/mime.types; + default_type application/octet-stream; + + log_format main '$remote_addr - $remote_user [$time_local] "$request" ' + '$status $body_bytes_sent "$http_referer" ' + '"$http_user_agent" "$http_x_forwarded_for"'; + + access_log /var/log/nginx/access.log main; + + sendfile on; + #tcp_nopush on; + + keepalive_timeout 65; + + + upstream api_server { + server 10.1.20.11; + server 10.1.20.12; + } + + + + server { + + listen 88; + root /var/www/public_html; + + location /private/ { + auth_jwt "Google account" token=$cookie_auth_token; + auth_jwt_key_file /etc/nginx/google_certs.jwk; + } + + location /f5demo/ { + auth_jwt "Google account" token=$cookie_auth_token; + auth_jwt_key_file /etc/nginx/google_certs.jwk; + proxy_pass http://api_server/; + } + + } + + +} + + diff --git "a/10 NGINX\350\256\244\350\257\201\346\216\210\346\235\203/lab1_implicit_flow_gcp/www/public_html/index.html" "b/10 NGINX\350\256\244\350\257\201\346\216\210\346\235\203/lab1_implicit_flow_gcp/www/public_html/index.html" new file mode 100644 index 0000000..f241270 --- /dev/null +++ "b/10 NGINX\350\256\244\350\257\201\346\216\210\346\235\203/lab1_implicit_flow_gcp/www/public_html/index.html" @@ -0,0 +1,37 @@ + + + + + Anxin Training NGINX OpenID Connect Demo by ColinJi + + + + + + +

Anxin Training NGINX OpenID Connect Demo by ColinJi

+
+

Login with a Google account then visit the private area.

+

Login with a Google account then proxy to f5demo.

+ + + +
+
+
+ + diff --git "a/10 NGINX\350\256\244\350\257\201\346\216\210\346\235\203/lab1_implicit_flow_gcp/www/public_html/js.cookie.js" "b/10 NGINX\350\256\244\350\257\201\346\216\210\346\235\203/lab1_implicit_flow_gcp/www/public_html/js.cookie.js" new file mode 100644 index 0000000..7f3dffd --- /dev/null +++ "b/10 NGINX\350\256\244\350\257\201\346\216\210\346\235\203/lab1_implicit_flow_gcp/www/public_html/js.cookie.js" @@ -0,0 +1,151 @@ +/*! + * JavaScript Cookie v2.1.2 + * https://github.com/js-cookie/js-cookie + * + * Copyright 2006, 2015 Klaus Hartl & Fagner Brack + * Released under the MIT license + */ +;(function (factory) { + if (typeof define === 'function' && define.amd) { + define(factory); + } else if (typeof exports === 'object') { + module.exports = factory(); + } else { + var OldCookies = window.Cookies; + var api = window.Cookies = factory(); + api.noConflict = function () { + window.Cookies = OldCookies; + return api; + }; + } +}(function () { + function extend () { + var i = 0; + var result = {}; + for (; i < arguments.length; i++) { + var attributes = arguments[ i ]; + for (var key in attributes) { + result[key] = attributes[key]; + } + } + return result; + } + + function init (converter) { + function api (key, value, attributes) { + var result; + if (typeof document === 'undefined') { + return; + } + + // Write + + if (arguments.length > 1) { + attributes = extend({ + path: '/' + }, api.defaults, attributes); + + if (typeof attributes.expires === 'number') { + var expires = new Date(); + expires.setMilliseconds(expires.getMilliseconds() + attributes.expires * 864e+5); + attributes.expires = expires; + } + + try { + result = JSON.stringify(value); + if (/^[\{\[]/.test(result)) { + value = result; + } + } catch (e) {} + + if (!converter.write) { + value = encodeURIComponent(String(value)) + .replace(/%(23|24|26|2B|3A|3C|3E|3D|2F|3F|40|5B|5D|5E|60|7B|7D|7C)/g, decodeURIComponent); + } else { + value = converter.write(value, key); + } + + key = encodeURIComponent(String(key)); + key = key.replace(/%(23|24|26|2B|5E|60|7C)/g, decodeURIComponent); + key = key.replace(/[\(\)]/g, escape); + + return (document.cookie = [ + key, '=', value, + attributes.expires && '; expires=' + attributes.expires.toUTCString(), // use expires attribute, max-age is not supported by IE + attributes.path && '; path=' + attributes.path, + attributes.domain && '; domain=' + attributes.domain, + attributes.secure ? '; secure' : '' + ].join('')); + } + + // Read + + if (!key) { + result = {}; + } + + // To prevent the for loop in the first place assign an empty array + // in case there are no cookies at all. Also prevents odd result when + // calling "get()" + var cookies = document.cookie ? document.cookie.split('; ') : []; + var rdecode = /(%[0-9A-Z]{2})+/g; + var i = 0; + + for (; i < cookies.length; i++) { + var parts = cookies[i].split('='); + var cookie = parts.slice(1).join('='); + + if (cookie.charAt(0) === '"') { + cookie = cookie.slice(1, -1); + } + + try { + var name = parts[0].replace(rdecode, decodeURIComponent); + cookie = converter.read ? + converter.read(cookie, name) : converter(cookie, name) || + cookie.replace(rdecode, decodeURIComponent); + + if (this.json) { + try { + cookie = JSON.parse(cookie); + } catch (e) {} + } + + if (key === name) { + result = cookie; + break; + } + + if (!key) { + result[name] = cookie; + } + } catch (e) {} + } + + return result; + } + + api.set = api; + api.get = function (key) { + return api(key); + }; + api.getJSON = function () { + return api.apply({ + json: true + }, [].slice.call(arguments)); + }; + api.defaults = {}; + + api.remove = function (key, attributes) { + api(key, '', extend(attributes, { + expires: -1 + })); + }; + + api.withConverter = init; + + return api; + } + + return init(function () {}); +})); diff --git "a/10 NGINX\350\256\244\350\257\201\346\216\210\346\235\203/lab1_implicit_flow_gcp/www/public_html/private/index.html" "b/10 NGINX\350\256\244\350\257\201\346\216\210\346\235\203/lab1_implicit_flow_gcp/www/public_html/private/index.html" new file mode 100644 index 0000000..86fc6a7 --- /dev/null +++ "b/10 NGINX\350\256\244\350\257\201\346\216\210\346\235\203/lab1_implicit_flow_gcp/www/public_html/private/index.html" @@ -0,0 +1,13 @@ + + + +It is a Private of F5 SE Colin + + + +

Private of F5 SE Colin

+

hello world!

+ + + + diff --git "a/10 NGINX\350\256\244\350\257\201\346\216\210\346\235\203/lab1_implicit_flow_gcp/www/public_html/private/npic.png" "b/10 NGINX\350\256\244\350\257\201\346\216\210\346\235\203/lab1_implicit_flow_gcp/www/public_html/private/npic.png" new file mode 100644 index 0000000000000000000000000000000000000000..a416ee02b97b784a40b4a5171c75baa4a18374dc GIT binary patch literal 2478 zcmV;f2~qZmP)K)jNvmh{`}cOei{J6( zfx?v8?cklytSX^Uvf94Q=heI4#u}YSC!kNR*t?$5u6w|cXSaS(t!w~^0AaOyDJoL+ z000QhNkl>0+un6h;XpYAPTIBH-LQRIRn=`u^{B1ELZLAcNADy?%5!rW{4~psYAN$Rf!`2S?u;$L5QfvTdVF<`LnEMn4mK%TGxFxf0M zqd&+ORuKa+x)9IRvfE%3L%|Tw6|y=RBrX}^xk?sCRpmPN<9YL1_xb$^UZQ~ORw7%rZHUBe8)u+qzHom-3?A>DZ4AV+Qe@ zpKUjxdQ0})UetZkzl`_qy8@X-+`rU)-oJ`vp0Kz<#4g11y?hX{h+_}MI6+l+54i)G zMHL~QGienGWEOFMsQX#`aN5NJnT248=M;8CEE5(tAf6N1&PxR{i>g9Ab7(O)oGJi+ ze$@S(ejIC3K_IgbJcnCWVRoI00+~fIz9BX)to~IP$SkV32G1U?W5t2Yf;TXufCe(E zJdjyvJU4wz^mUIP6&5#?W>5H9%^nuWEVO#A`?=P|V)@WOW@&0Xe{~9vZx(^zf6a^M z?K1+Ig~oHks=DQq0+~hJH|k<=ZPehHqU;;gn_HRlg&u{ttoyk?kM@HvL{h+YKlkUc zsUwsF%gvc0dXEl86je1xJ*|jXRI^__u{rkyGhGm@ey`WsBZIMFGnJ%A9Sz+Gl7c z;VO8WUL}I%i-_oCihTWZmin52a=L=X)u`IkL4@QG!J_Rfb^W=9{f@Lm6EH4u4Ik3#9h-KkD z>FOCQ^C@IGvCsg^e2Q5X*8EBsEb}R7Iib)1%Y2Gj<`)`ZnNMNMiw>vI0Ly#|Tc(%K zafM)+PjSn_Ydo64GM^Hbg|Aql0hamXu^gMG5-T*oGM_w_cQGx|LIW)G$z%ETzv!)# z#V1>6fMq_pEE}EZjM#V9BUt8>%Q9BF(QIZ54Y157pJk-}iyq)5Ja7b-`Q)^W@LTi< z$51^7migqhjEtC@*{#q3%Y1TMMq+fT=3;X#G{7>S{FVud78)&dkqMUh*R{_h36tql~ z=$j&aqhOg&LCZ+##0m`qEGJRaGE%zHLwy)vIf25Kk@y`wRvRl|nM-lY2*>UUeq*rA zrG#Z(p#he;l(CGAXrZxS-|+yJ14>yYB)ZfS`#o3=C}kPN?@%#-<$!XQk$Orvt`Ara zC}|ntw6#PUZ`sy+y7#%PWn`qRztD8cJyUmO)2+ZV!pTdrH{7z^AL{No%ShQI6&lU9?DmAdEcAQAv)Wx>?whn`hMCFes3Zx!06Tc(Ds zsdrgYk!Aj}osGAAA>A@N@8XcQN;9v}c!zb1&ZJt7tXuS*zCccFDh#Y!bRpF;Qp3aa zi+%d~Tk$(oum)E^x@D#_AG4Nqk7_=^dU63-;%)<*@%K>1Tc5&z0zWcd6|fu7SbdqO z>V3;KH^_3GYl$~!a~N0`{~5p@4^QE%uKh|r8?;}Ew>s+cHtM>8KO43K-FubWGT(<9 ze`Csnkj=66r2i_5-Cg?%RE8qv+UeHr`RHzeXEv3b!IU`+MH6g2pvWUv^n@0+Yx5s)rOEL6_2n?5o}dR`kH)#qq%^JXC&jba$-4u&CXHne%aJsG z3z>@J(wA-zxWQp$Src?=-1kZNxyP~XK4st4WA4&Ilg#rMvNYwlkflV+x9;y=4nxtC zj`Rc$kJ)fM0F61i7}RB`q7@y1}TZ*G5_dMCGWoO{w&`v(|YmNS-)_7i48_zV5%M5aAG#<`fuXpoi`j!JpVapfwy3~tV zo_Gvy*Mj!INhq|R!h4nRtfF$m^_n#CYg^fi(M-$k)pD#an_flY7bRM7&1WT5;7_8m zO|r{xeXWH8wWQ?>lhL^kThencvE#gSDu@kQA(!69Jz`n*KSwNI%eYHXeKwzD*_1Ap z>nk$?7E7_@MR&mKamm`L*G-cwPlL`ssWq1aRo`KTdmc(87|&?ogv2g=EY0FJVs`x@PEipiW+k$8-5W4$zp9Gq2Qjq=_}6 zmPgauKaM7s7N*zWJQ&v>g)EOkFP7{dMfxd2&%zffR6Q%=ymTN3*z72<-Lov(Z*`kK zaH|m9P$RcL?Vs%q_0Wh1dl=cWdbNl0jm0s4JQKWW&NP6E$Q{qB`m7sHe~Mk6cvg(> zhTS=>j4yO&^-STxhSk5!c&35esJSc;VV8c(3Ie$z+9Y{r zTL|RJXuV;6JVPK?%9c0bOI6zt$knn#k$6^&69jVgFf$5>*v&U33%HX|^(^jF)`tSh sLE~8=goqdd`JrszHlOn~1adb21Es~Sg3(ji2wiq literal 0 HcmV?d00001 -- Gitee From 5fbadfb0dccab43685067b6325c63c1ba7f58136 Mon Sep 17 00:00:00 2001 From: xtomrfx Date: Thu, 30 Sep 2021 10:42:54 +0800 Subject: [PATCH 06/23] 2nd --- .../lab1_implicit_flow_gcp/nginx.conf" | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git "a/10 NGINX\350\256\244\350\257\201\346\216\210\346\235\203/lab1_implicit_flow_gcp/nginx.conf" "b/10 NGINX\350\256\244\350\257\201\346\216\210\346\235\203/lab1_implicit_flow_gcp/nginx.conf" index 125b713..714684b 100644 --- "a/10 NGINX\350\256\244\350\257\201\346\216\210\346\235\203/lab1_implicit_flow_gcp/nginx.conf" +++ "b/10 NGINX\350\256\244\350\257\201\346\216\210\346\235\203/lab1_implicit_flow_gcp/nginx.conf" @@ -22,7 +22,7 @@ http { access_log /var/log/nginx/access.log main; sendfile on; - #tcp_nopush on; + keepalive_timeout 65; -- Gitee From c2a79f8ebd85ce2ca376ed4464c914cad722b777 Mon Sep 17 00:00:00 2001 From: xtomrfx Date: Thu, 30 Sep 2021 11:08:46 +0800 Subject: [PATCH 07/23] lab1 guide --- .../lab1_implicit_flow_gcp/README.md" | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git "a/10 NGINX\350\256\244\350\257\201\346\216\210\346\235\203/lab1_implicit_flow_gcp/README.md" "b/10 NGINX\350\256\244\350\257\201\346\216\210\346\235\203/lab1_implicit_flow_gcp/README.md" index 5484746..4193569 100644 --- "a/10 NGINX\350\256\244\350\257\201\346\216\210\346\235\203/lab1_implicit_flow_gcp/README.md" +++ "b/10 NGINX\350\256\244\350\257\201\346\216\210\346\235\203/lab1_implicit_flow_gcp/README.md" @@ -1,6 +1,13 @@ # Lab环境介绍 -本次演示和实验采用Docker环境,学员可根据自己实际情况准备实验环境。本环境中包含以下组件: +本次演示的是利用Nginx Plus实现OAUTH2.0 Implicit Flow流程的认证授权。具体细节: +`client --- nginx plus --- resouce server` + | + | +- Nginx Plus自身有一个存放静态页面的目录,同时也作为后端资源的一个反代。 +- 用户通过Nginx Plus上的一个静态主页,可以访问以上的两个资源。 +- 如果访问这两个资源,都需要通过GCP的OIDC的认证,获取到access token。 NGINX PLUS验证access token后,放行对资源的访问。 + ## NGINX Plus反向代理服务器 后面简称反代,可通过*Dockerfile*生成容器镜像,容器暴露端口如下: -- Gitee From 1962b15f0e0fd281ea5ad3ccc5f492a3ae902d71 Mon Sep 17 00:00:00 2001 From: xtomrfx Date: Thu, 30 Sep 2021 11:24:32 +0800 Subject: [PATCH 08/23] lab1guide --- .../lab1_implicit_flow_gcp/README.md" | 37 ++++++++++++++----- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git "a/10 NGINX\350\256\244\350\257\201\346\216\210\346\235\203/lab1_implicit_flow_gcp/README.md" "b/10 NGINX\350\256\244\350\257\201\346\216\210\346\235\203/lab1_implicit_flow_gcp/README.md" index 4193569..4cc5613 100644 --- "a/10 NGINX\350\256\244\350\257\201\346\216\210\346\235\203/lab1_implicit_flow_gcp/README.md" +++ "b/10 NGINX\350\256\244\350\257\201\346\216\210\346\235\203/lab1_implicit_flow_gcp/README.md" @@ -1,20 +1,39 @@ # Lab环境介绍 -本次演示的是利用Nginx Plus实现OAUTH2.0 Implicit Flow流程的认证授权。具体细节: -`client --- nginx plus --- resouce server` - | - | +本次演示的是利用Nginx Plus实现OAUTH2.0 Implicit Flow流程的认证授权。具体细节: +`client --- nginx plus --- resouce server` +      `GCP Author API` + - Nginx Plus自身有一个存放静态页面的目录,同时也作为后端资源的一个反代。 - 用户通过Nginx Plus上的一个静态主页,可以访问以上的两个资源。 - 如果访问这两个资源,都需要通过GCP的OIDC的认证,获取到access token。 NGINX PLUS验证access token后,放行对资源的访问。 -## NGINX Plus反向代理服务器 -后面简称反代,可通过*Dockerfile*生成容器镜像,容器暴露端口如下: -- Web服务:8080:80 -- API:8000:8000 +## NGINX Plus配置说明 + +1. 监听端口 88;按需修改 +2. 主页资源目录放在 /var/www/中 + + +```nginx +server { + + listen 88; + root /var/www/public_html; + + location /private/ { + auth_jwt "Google account" token=$cookie_auth_token; + auth_jwt_key_file /etc/nginx/google_certs.jwk; + } + + location /f5demo/ { + auth_jwt "Google account" token=$cookie_auth_token; + auth_jwt_key_file /etc/nginx/google_certs.jwk; + proxy_pass http://api_server/; + } -容器启动后,登录容器,在/etc/nginx/conf.d/目录下创建 *api-8000.conf* ,执行 `nginx -s reload` ,在实验客户端访问 http://x.x.x.x:8080 确认可以看到NGINX欢迎页面,访问 http://x.x.x.x:8000 ,确认可以打开Dashboard。x.x.x.x为Docker服务器的IP,也即反代的IP,下同。 + } +``` ## Web Servers 后面简称Web,可直接使用和反代相同的N+镜像,不对外暴露端口,使用Docker网桥和N+反代通信 -- Gitee From 3116952bb1ce11c736a58059ed98c7fffb78e583 Mon Sep 17 00:00:00 2001 From: xtomrfx Date: Thu, 30 Sep 2021 11:33:33 +0800 Subject: [PATCH 09/23] lab1guide --- .../lab1_implicit_flow_gcp/README.md" | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git "a/10 NGINX\350\256\244\350\257\201\346\216\210\346\235\203/lab1_implicit_flow_gcp/README.md" "b/10 NGINX\350\256\244\350\257\201\346\216\210\346\235\203/lab1_implicit_flow_gcp/README.md" index 4cc5613..0b822e7 100644 --- "a/10 NGINX\350\256\244\350\257\201\346\216\210\346\235\203/lab1_implicit_flow_gcp/README.md" +++ "b/10 NGINX\350\256\244\350\257\201\346\216\210\346\235\203/lab1_implicit_flow_gcp/README.md" @@ -1,8 +1,8 @@ # Lab环境介绍 本次演示的是利用Nginx Plus实现OAUTH2.0 Implicit Flow流程的认证授权。具体细节: -`client --- nginx plus --- resouce server` -      `GCP Author API` +Client --- Nginx Plus --- Resouce Server + |------GCP Author API - Nginx Plus自身有一个存放静态页面的目录,同时也作为后端资源的一个反代。 - 用户通过Nginx Plus上的一个静态主页,可以访问以上的两个资源。 @@ -14,7 +14,7 @@ 1. 监听端口 88;按需修改 2. 主页资源目录放在 /var/www/中 - + ```nginx server { -- Gitee From 20a0e6aefc7c5d1b9d7787ac09ba69e6087997d9 Mon Sep 17 00:00:00 2001 From: xtomrfx Date: Thu, 30 Sep 2021 11:39:37 +0800 Subject: [PATCH 10/23] lab1guide --- .../lab1_implicit_flow_gcp/README.md" | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git "a/10 NGINX\350\256\244\350\257\201\346\216\210\346\235\203/lab1_implicit_flow_gcp/README.md" "b/10 NGINX\350\256\244\350\257\201\346\216\210\346\235\203/lab1_implicit_flow_gcp/README.md" index 0b822e7..c365d0c 100644 --- "a/10 NGINX\350\256\244\350\257\201\346\216\210\346\235\203/lab1_implicit_flow_gcp/README.md" +++ "b/10 NGINX\350\256\244\350\257\201\346\216\210\346\235\203/lab1_implicit_flow_gcp/README.md" @@ -1,8 +1,8 @@ # Lab环境介绍 本次演示的是利用Nginx Plus实现OAUTH2.0 Implicit Flow流程的认证授权。具体细节: -Client --- Nginx Plus --- Resouce Server - |------GCP Author API + + - Nginx Plus自身有一个存放静态页面的目录,同时也作为后端资源的一个反代。 - 用户通过Nginx Plus上的一个静态主页,可以访问以上的两个资源。 @@ -13,6 +13,9 @@ 1. 监听端口 88;按需修改 2. 主页资源目录放在 /var/www/中 +3. /private/资源是静态页面,资源存放在/var/www下。/f5demo/资源是做了反代,转发到后台api server资源。 +4. 去以上资源都需要通过jwt token的效验。 其中用于验证jwt token的key文件存放在/etc/nginx/下。 +5. nginx plus收到请求会通过`token=$cookie_auth_token;`定义的变量,从http头部的cookie获取`name=auth_token`的cookie值 ```nginx -- Gitee From 8f46df570c318af8ee7fa56ec59a5997c5d69129 Mon Sep 17 00:00:00 2001 From: xtomrfx Date: Thu, 30 Sep 2021 12:59:57 +0800 Subject: [PATCH 11/23] lab1guide --- .../lab1_implicit_flow_gcp/README.md" | 214 +++++------------- 1 file changed, 61 insertions(+), 153 deletions(-) diff --git "a/10 NGINX\350\256\244\350\257\201\346\216\210\346\235\203/lab1_implicit_flow_gcp/README.md" "b/10 NGINX\350\256\244\350\257\201\346\216\210\346\235\203/lab1_implicit_flow_gcp/README.md" index c365d0c..8c5423f 100644 --- "a/10 NGINX\350\256\244\350\257\201\346\216\210\346\235\203/lab1_implicit_flow_gcp/README.md" +++ "b/10 NGINX\350\256\244\350\257\201\346\216\210\346\235\203/lab1_implicit_flow_gcp/README.md" @@ -11,13 +11,7 @@ ## NGINX Plus配置说明 -1. 监听端口 88;按需修改 -2. 主页资源目录放在 /var/www/中 -3. /private/资源是静态页面,资源存放在/var/www下。/f5demo/资源是做了反代,转发到后台api server资源。 -4. 去以上资源都需要通过jwt token的效验。 其中用于验证jwt token的key文件存放在/etc/nginx/下。 -5. nginx plus收到请求会通过`token=$cookie_auth_token;`定义的变量,从http头部的cookie获取`name=auth_token`的cookie值 - - +nginx部分配置: ```nginx server { @@ -37,15 +31,68 @@ server { } ``` +1. 监听端口 88;按需修改 +2. 主页资源目录放在 `/var/www/`中 +3. `/private/`资源是静态页面,资源存放在`/var/www`下。`/f5demo/`资源是做了反代,转发到后台api server资源。 +4. 去以上资源都需要通过jwt token的效验。 其中用于验证jwt token的key文件存放在`/etc/nginx/`下。 +5. nginx plus收到请求会通过`token=$cookie_auth_token;`定义的变量,从http头部的cookie获取`name=auth_token`的cookie值 -## Web Servers -后面简称Web,可直接使用和反代相同的N+镜像,不对外暴露端口,使用Docker网桥和N+反代通信 +6. 获取google token验证用的key: + ``` + 0 * * * * wget https://www.googleapis.com/oauth2/v3/certs -O /etc/nginx/google_certs.jwk + ``` + google key会定期更新,可以如上写一个crontab来定期更新获取jwt key。 + + +## HTML登录主页说明 +对在`/var/www/public_html/index.html`进行说明: +```html + + + + + Anxin Training NGINX OpenID Connect Demo by ColinJi + + + + + + +

Anxin Training NGINX OpenID Connect Demo by ColinJi

+
+

Login with a Google account then visit the private area.

+

Login with a Google account then proxy to f5demo.

+ + + +
+
+
+ + +``` -## 测试客户端 -请预装以下软件,并且为了方便测试,建议在客户端hosts配置测试所用域名。 -- curl -- wrk -- 浏览器 +核心部分说明: +```html + + + +``` --- @@ -56,142 +103,3 @@ NGINX安装目录为/etc/nginx/,所有实验配置文件均保存在/etc/nginx 请修改实验客户端*hosts*文件,将实验相关域名解析到反代的IP,反代IP设定为x.x.x.x。 ## Lab1 变量 -1. 在反代中创建 *variable.conf* 文件,执行 `nginx -s reload` ,观察配置文件是否能被加载。 - -2. 访问http://variable.will.com:8080/noset 和 http://variable.will.com:8080/set ,观察返回的页面信息。 - -3. 删除 *variable.conf* 中第4行的注释符 - ``` - set $f5 "is the best ADC!"; - ``` - 重复第1、2步。 - -4. 在 *variable.conf* 中第11行增加注释符 - ``` - #set $f5 "NGINX is a part of F5"; - ``` - 重复第1步。 - -## Lab2 蓝绿部署 -1. 在反代中创建 *bluegreen.conf* 文件,upstream *blue* 和 *green* 分别修改为Web1和Web2的容器IP,执行 `nginx -s reload`。 -2. 在实验客户端执行以下命令,观察输出,应该为空。 - ``` - curl http://x.x.x.x:8000/api/6/http/keyvals/blue-green - ``` -3. 访问 http://bluegreen.will.com:8080 ,应该访问到Web1。 -4. 在实验客户端执行以下命令。 - ``` - curl -X POST -d '{"environment": "green"} http://x.x.x.x:8000/api/6/http/keyvals/blue-green - ``` -5. 访问 http://bluegreen.will.com:8080 ,应该访问到Web2。 -6. 在实验客户端执行以下命令。 - ``` - curl -X PATCH -d '{"environment": "blue"} http://x.x.x.x:8000/api/6/http/keyvals/blue-green - ``` -7. 访问 http://bluegreen.will.com:8080 ,应该访问到Web1。 - -## Lab3 AB Test -1. 在反代中创建 *abtest.conf* 文件,upstream *abtest_a* 和 *abtest_b* 分别修改为Web1和Web2的容器IP,执行 `nginx -s reload`。 -2. 在实验客户端通过wrk打压力,参考命令 `wrk -c200 -t8 -d300s "http://abtest.will.com:8080" ,打开Dashboard,观察upstream,所有的request应该都打向abtest_a。 -3. 在实验客户端执行以下命令。 - ``` - curl -X POST -d '{"bpercentage": 5} http://x.x.x.x:8000/api/6/http/keyvals/abtest - ``` -4. 通过Dashboard,观察upstream,应该有5%左右的request打向abtest_b。 -5. 在实验客户端执行以下命令。 - ``` - curl -X PATCH -d '{"bpercentage": 20} http://x.x.x.x:8000/api/6/http/keyvals/abtest - ``` -6. 通过Dashboard,观察upstream,应该有20%左右的request打向abtest_b。 -7. 在实验客户端执行以下命令。 - ``` - curl -X PATCH -d '{"bpercentage": 50} http://x.x.x.x:8000/api/6/http/keyvals/abtest - ``` -8. 通过Dashboard,观察upstream,应该有50%左右的request打向abtest_b。 -9. 在实验客户端执行以下命令。 - ``` - curl -X PATCH -d '{"bpercentage": 100} http://x.x.x.x:8000/api/6/http/keyvals/abtest - ``` -10. 通过Dashboard,观察upstream,应该所有的request都打向abtest_b。 - -## Lab4 灰度发布 -1. 在反代中创建 *canary.conf* 文件,upstream *v1_only* 、 *v2_only* 、 *all* 分别修改为Web1和Web2的容器IP,执行 `nginx -s reload`。 -2. 在实验客户端多次用curl模拟各种浏览器访问,应该在Web1和Web2之间轮询。 - ``` - curl -A 'Chrome' http://canary.will.com:8080 - ``` -3. 在实验客户端执行以下命令。 - ``` - curl -X POST -d '{"stage": "b"} http://x.x.x.x:8000/api/6/http/keyvals/canary - ``` -4. 在实验客户端多次用curl模拟各种浏览器访问,应该只会访问到Web1。 - ``` - curl -A 'Chrome' http://canary.will.com:8080 - ``` -5. 在实验客户端执行以下命令。 - ``` - curl -X PATCH -d '{"stage": "c"} http://x.x.x.x:8000/api/6/http/keyvals/canary - ``` -6. 在实验客户端多次用curl模拟Chrome浏览器访问,应该只会访问到Web2。 - ``` - curl -A 'Chrome' http://canary.will.com:8080 - ``` -7. 在实验客户端多次用curl模拟Firefox浏览器访问,应该只会访问到Web1。 - ``` - curl -A 'Firefox' http://canary.will.com:8080 - ``` -8. 在实验客户端模拟其它浏览器访问,例如Safari,应该也只会访问到Web1。 -9. 在实验客户端执行以下命令。 - ``` - curl -X PATCH -d '{"stage": "d"} http://x.x.x.x:8000/api/6/http/keyvals/canary - ``` -10. 在实验客户端多次用curl模拟各种浏览器访问,应该只会访问到Web2。 -11. 在实验客户端执行以下命令。 - ``` - curl -X PATCH -d '{"stage": "a"} http://x.x.x.x:8000/api/6/http/keyvals/canary - ``` -12. 在实验客户端多次用curl模拟各种浏览器访问,应该在Web1和Web2之间轮询。 - -## Lab5 动态限流 -1. 在反代中创建 *ratelimit.conf* 文件,upstream *ratelimit* 分别修改为Web1和Web2的容器IP,执行 `nginx -s reload`。 -2. 在实验客户端通过wrk打压力,参考命令 `wrk -c200 -t8 -d300s "http://ratelimit.will.com:8080" ,打开Dashboard观察,此时应该是正常分发流量,没有任何限速。 -3. 在实验客户端执行以下命令,打开限速200rps的开关。 - ``` - curl -X POST -d '{"ratelimit_200": 1} http://x.x.x.x:8000/api/6/http/keyvals/kv_ratelimit - ``` -4. 打压力的同时观察Dashboard,应该被限制在了200rps左右,同时观察delay的效果。 -5. 在实验客户端执行以下命令,打开限速100rps的开关。 - ``` - curl -X POST -d '{"ratelimit_100": 1} http://x.x.x.x:8000/api/6/http/keyvals/kv_ratelimit - ``` -6. 打压力的同时观察Dashboard,应该被限制在了100rps左右,同时观察nodelay的效果。 - -## Lab6 熔断 -1. 在反代中创建 *circuitbreaker.conf* 文件,upstream *circuitbreaker* 分别修改为Web1和Web2的容器IP,执行 `nginx -s reload`。 -2. 打开Dashboard,观察健康检查的情况。 -3. 在实验客户端通过wrk打压力,参考命令 `wrk -c200 -t8 -d300s "http://circuit.will.com:8080" ,打开Dashboard观察,此时应该是正常分发流量。 -4. 登录Web2容器,修改 */etc/nginx/conf.d/default.conf* 文件,将以下部分中return的值做任意改变,执行 `nginx -s reload`。 - ``` - location /health { - default_type application/json; - return 200 '{"deadlocks":{"healthy":true},"Disk":{"healthy":false},"Memory":{"healthy":true}}'; - } - ``` -5. 观察Dashboard,Web2应该被健康检查标记为down,流量全部打向Web1。 -6. 登录Web2容器,将 */etc/nginx/conf.d/default.conf* 文件修改为正常值,执行 `nginx -s reload`。 - ``` - location /health { - default_type application/json; - return 200 '{"deadlocks":{"healthy":true},"Disk":{"healthy":true},"Memory":{"healthy":true}}'; - } - ``` -7. 观察Dashboard,Web2连续三次健康检查通过后应该被重新标记为up,并且开始逐步接收流量,最终和Web1达到1:1。 -8. 删除反代 *circuitbreaker.conf* 文件中的slow_start参数,执行 `nginx -s reload`。 - ``` - upstream circuitbreaker { - server 172.17.0.3:80; - server 172.17.0.4:80; - zone circuitbreaker 64k; - } - ``` -9. 重复4至7步,观察没有slow_start时候的效果。 -- Gitee From 51beb0096aaa3a303698cbfa773793b7fb758017 Mon Sep 17 00:00:00 2001 From: xtomrfx Date: Thu, 30 Sep 2021 13:38:49 +0800 Subject: [PATCH 12/23] lab1guide --- .../lab1_implicit_flow_gcp/README.md" | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git "a/10 NGINX\350\256\244\350\257\201\346\216\210\346\235\203/lab1_implicit_flow_gcp/README.md" "b/10 NGINX\350\256\244\350\257\201\346\216\210\346\235\203/lab1_implicit_flow_gcp/README.md" index 8c5423f..29faed4 100644 --- "a/10 NGINX\350\256\244\350\257\201\346\216\210\346\235\203/lab1_implicit_flow_gcp/README.md" +++ "b/10 NGINX\350\256\244\350\257\201\346\216\210\346\235\203/lab1_implicit_flow_gcp/README.md" @@ -45,7 +45,7 @@ server { ## HTML登录主页说明 -对在`/var/www/public_html/index.html`进行说明: +对在`/var/www/public_html/index.html`内容进行说明: ```html @@ -93,13 +93,12 @@ server { content="输入你的clientid"> ``` +- `google-signin-client_id` tag : 使用google的oauth2.0 JS API,这里需要提供注册后获取的clientid +- `js.cookie.js` : 轻量的js用于解析access token,并在请求中作为cookie的值。在后面使用的`cookie.set` 就是利用了这个库 + --- # 实验步骤 -NGINX安装目录为/etc/nginx/,所有实验配置文件均保存在/etc/nginx/conf.d/目录下。 - -请修改实验客户端*hosts*文件,将实验相关域名解析到反代的IP,反代IP设定为x.x.x.x。 - -## Lab1 变量 +## Google GCP API 注册 -- Gitee From db01f17a1b3cedc6098f2b8afe53f255af8f48e8 Mon Sep 17 00:00:00 2001 From: xtomrfx Date: Thu, 30 Sep 2021 05:42:10 +0000 Subject: [PATCH 13/23] =?UTF-8?q?update=2010=20NGINX=E8=AE=A4=E8=AF=81?= =?UTF-8?q?=E6=8E=88=E6=9D=83/lab1=5Fimplicit=5Fflow=5Fgcp/README.md.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lab1_implicit_flow_gcp/README.md" | 1 + 1 file changed, 1 insertion(+) diff --git "a/10 NGINX\350\256\244\350\257\201\346\216\210\346\235\203/lab1_implicit_flow_gcp/README.md" "b/10 NGINX\350\256\244\350\257\201\346\216\210\346\235\203/lab1_implicit_flow_gcp/README.md" index 29faed4..1dea6f4 100644 --- "a/10 NGINX\350\256\244\350\257\201\346\216\210\346\235\203/lab1_implicit_flow_gcp/README.md" +++ "b/10 NGINX\350\256\244\350\257\201\346\216\210\346\235\203/lab1_implicit_flow_gcp/README.md" @@ -102,3 +102,4 @@ server { # 实验步骤 ## Google GCP API 注册 +![Image description](https://images.gitee.com/uploads/images/2021/0930/134203_93592ed4_9655714.png "屏幕截图.png") -- Gitee From c4b27da23983b8794cc06e818c10679eda38846f Mon Sep 17 00:00:00 2001 From: xtomrfx Date: Thu, 30 Sep 2021 05:47:09 +0000 Subject: [PATCH 14/23] =?UTF-8?q?update=2010=20NGINX=E8=AE=A4=E8=AF=81?= =?UTF-8?q?=E6=8E=88=E6=9D=83/lab1=5Fimplicit=5Fflow=5Fgcp/README.md.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lab1_implicit_flow_gcp/README.md" | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git "a/10 NGINX\350\256\244\350\257\201\346\216\210\346\235\203/lab1_implicit_flow_gcp/README.md" "b/10 NGINX\350\256\244\350\257\201\346\216\210\346\235\203/lab1_implicit_flow_gcp/README.md" index 1dea6f4..e35c359 100644 --- "a/10 NGINX\350\256\244\350\257\201\346\216\210\346\235\203/lab1_implicit_flow_gcp/README.md" +++ "b/10 NGINX\350\256\244\350\257\201\346\216\210\346\235\203/lab1_implicit_flow_gcp/README.md" @@ -102,4 +102,13 @@ server { # 实验步骤 ## Google GCP API 注册 + + +建立一个新的project,起名字后确认 +![Image description](https://images.gitee.com/uploads/images/2021/0930/134455_9d56be50_9655714.png "屏幕截图.png") + +进入API library ![Image description](https://images.gitee.com/uploads/images/2021/0930/134203_93592ed4_9655714.png "屏幕截图.png") + +选择social里的google+ api +![Image description](https://images.gitee.com/uploads/images/2021/0930/134705_737a4f10_9655714.png "屏幕截图.png") \ No newline at end of file -- Gitee From 1778887da46f7a3e6b635f7bec8804b255b614d5 Mon Sep 17 00:00:00 2001 From: xtomrfx Date: Thu, 30 Sep 2021 05:47:46 +0000 Subject: [PATCH 15/23] =?UTF-8?q?update=2010=20NGINX=E8=AE=A4=E8=AF=81?= =?UTF-8?q?=E6=8E=88=E6=9D=83/lab1=5Fimplicit=5Fflow=5Fgcp/README.md.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lab1_implicit_flow_gcp/README.md" | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git "a/10 NGINX\350\256\244\350\257\201\346\216\210\346\235\203/lab1_implicit_flow_gcp/README.md" "b/10 NGINX\350\256\244\350\257\201\346\216\210\346\235\203/lab1_implicit_flow_gcp/README.md" index e35c359..85c2dd2 100644 --- "a/10 NGINX\350\256\244\350\257\201\346\216\210\346\235\203/lab1_implicit_flow_gcp/README.md" +++ "b/10 NGINX\350\256\244\350\257\201\346\216\210\346\235\203/lab1_implicit_flow_gcp/README.md" @@ -104,11 +104,11 @@ server { ## Google GCP API 注册 -建立一个新的project,起名字后确认 +建立一个新的project,起名字后确认 ![Image description](https://images.gitee.com/uploads/images/2021/0930/134455_9d56be50_9655714.png "屏幕截图.png") -进入API library +进入API library ![Image description](https://images.gitee.com/uploads/images/2021/0930/134203_93592ed4_9655714.png "屏幕截图.png") -选择social里的google+ api +选择social里的google+ api ![Image description](https://images.gitee.com/uploads/images/2021/0930/134705_737a4f10_9655714.png "屏幕截图.png") \ No newline at end of file -- Gitee From 118be018b2da22b1507784db5c833070f5310454 Mon Sep 17 00:00:00 2001 From: xtomrfx Date: Thu, 30 Sep 2021 05:48:24 +0000 Subject: [PATCH 16/23] =?UTF-8?q?update=2010=20NGINX=E8=AE=A4=E8=AF=81?= =?UTF-8?q?=E6=8E=88=E6=9D=83/lab1=5Fimplicit=5Fflow=5Fgcp/README.md.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lab1_implicit_flow_gcp/README.md" | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git "a/10 NGINX\350\256\244\350\257\201\346\216\210\346\235\203/lab1_implicit_flow_gcp/README.md" "b/10 NGINX\350\256\244\350\257\201\346\216\210\346\235\203/lab1_implicit_flow_gcp/README.md" index 85c2dd2..17ed58d 100644 --- "a/10 NGINX\350\256\244\350\257\201\346\216\210\346\235\203/lab1_implicit_flow_gcp/README.md" +++ "b/10 NGINX\350\256\244\350\257\201\346\216\210\346\235\203/lab1_implicit_flow_gcp/README.md" @@ -104,11 +104,14 @@ server { ## Google GCP API 注册 -建立一个新的project,起名字后确认 +- 建立一个新的project,起名字后确认 + ![Image description](https://images.gitee.com/uploads/images/2021/0930/134455_9d56be50_9655714.png "屏幕截图.png") -进入API library +- 进入API library + ![Image description](https://images.gitee.com/uploads/images/2021/0930/134203_93592ed4_9655714.png "屏幕截图.png") -选择social里的google+ api +- 选择social里的google+ api + ![Image description](https://images.gitee.com/uploads/images/2021/0930/134705_737a4f10_9655714.png "屏幕截图.png") \ No newline at end of file -- Gitee From 869c538d7d3f73e1ebffd366b7776a28e3b258d6 Mon Sep 17 00:00:00 2001 From: xtomrfx Date: Thu, 30 Sep 2021 05:51:01 +0000 Subject: [PATCH 17/23] =?UTF-8?q?update=2010=20NGINX=E8=AE=A4=E8=AF=81?= =?UTF-8?q?=E6=8E=88=E6=9D=83/lab1=5Fimplicit=5Fflow=5Fgcp/README.md.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lab1_implicit_flow_gcp/README.md" | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git "a/10 NGINX\350\256\244\350\257\201\346\216\210\346\235\203/lab1_implicit_flow_gcp/README.md" "b/10 NGINX\350\256\244\350\257\201\346\216\210\346\235\203/lab1_implicit_flow_gcp/README.md" index 17ed58d..fd465d3 100644 --- "a/10 NGINX\350\256\244\350\257\201\346\216\210\346\235\203/lab1_implicit_flow_gcp/README.md" +++ "b/10 NGINX\350\256\244\350\257\201\346\216\210\346\235\203/lab1_implicit_flow_gcp/README.md" @@ -112,6 +112,12 @@ server { ![Image description](https://images.gitee.com/uploads/images/2021/0930/134203_93592ed4_9655714.png "屏幕截图.png") -- 选择social里的google+ api +- 选择social里的google+ api ,点击进入并enable 启用API + +![Image description](https://images.gitee.com/uploads/images/2021/0930/134705_737a4f10_9655714.png "屏幕截图.png") + +- 在API菜单的credential里,建立openid connect类型的API endpoint + +![Image description](https://images.gitee.com/uploads/images/2021/0930/135049_943398e8_9655714.png "屏幕截图.png") + -![Image description](https://images.gitee.com/uploads/images/2021/0930/134705_737a4f10_9655714.png "屏幕截图.png") \ No newline at end of file -- Gitee From ef54559dce22581d7f62bd808c2f8be40d527bdd Mon Sep 17 00:00:00 2001 From: xtomrfx Date: Thu, 30 Sep 2021 05:53:22 +0000 Subject: [PATCH 18/23] =?UTF-8?q?update=2010=20NGINX=E8=AE=A4=E8=AF=81?= =?UTF-8?q?=E6=8E=88=E6=9D=83/lab1=5Fimplicit=5Fflow=5Fgcp/README.md.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lab1_implicit_flow_gcp/README.md" | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git "a/10 NGINX\350\256\244\350\257\201\346\216\210\346\235\203/lab1_implicit_flow_gcp/README.md" "b/10 NGINX\350\256\244\350\257\201\346\216\210\346\235\203/lab1_implicit_flow_gcp/README.md" index fd465d3..19b5db1 100644 --- "a/10 NGINX\350\256\244\350\257\201\346\216\210\346\235\203/lab1_implicit_flow_gcp/README.md" +++ "b/10 NGINX\350\256\244\350\257\201\346\216\210\346\235\203/lab1_implicit_flow_gcp/README.md" @@ -101,7 +101,7 @@ server { # 实验步骤 -## Google GCP API 注册 +## Google GCP上注册应用 - 建立一个新的project,起名字后确认 @@ -120,4 +120,6 @@ server { ![Image description](https://images.gitee.com/uploads/images/2021/0930/135049_943398e8_9655714.png "屏幕截图.png") +- 这时候会分配clientid和client secret给用户,好好保存。并且填写好回传的URL +![Image description](https://images.gitee.com/uploads/images/2021/0930/135309_81514ca9_9655714.png "屏幕截图.png") -- Gitee From 2745e1eebeed9f232cf2926a5c0b29e8b2af1ea0 Mon Sep 17 00:00:00 2001 From: xtomrfx Date: Thu, 30 Sep 2021 05:57:58 +0000 Subject: [PATCH 19/23] =?UTF-8?q?update=2010=20NGINX=E8=AE=A4=E8=AF=81?= =?UTF-8?q?=E6=8E=88=E6=9D=83/lab1=5Fimplicit=5Fflow=5Fgcp/README.md.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lab1_implicit_flow_gcp/README.md" | 6 ++++++ 1 file changed, 6 insertions(+) diff --git "a/10 NGINX\350\256\244\350\257\201\346\216\210\346\235\203/lab1_implicit_flow_gcp/README.md" "b/10 NGINX\350\256\244\350\257\201\346\216\210\346\235\203/lab1_implicit_flow_gcp/README.md" index 19b5db1..9d26563 100644 --- "a/10 NGINX\350\256\244\350\257\201\346\216\210\346\235\203/lab1_implicit_flow_gcp/README.md" +++ "b/10 NGINX\350\256\244\350\257\201\346\216\210\346\235\203/lab1_implicit_flow_gcp/README.md" @@ -123,3 +123,9 @@ server { - 这时候会分配clientid和client secret给用户,好好保存。并且填写好回传的URL ![Image description](https://images.gitee.com/uploads/images/2021/0930/135309_81514ca9_9655714.png "屏幕截图.png") + +- 配置授权认证时候显示的提示面板 + +![Image description](https://images.gitee.com/uploads/images/2021/0930/135746_6219bf8f_9655714.png "屏幕截图.png") + + -- Gitee From 2a0b9b25c0d1ac37c6d3976f24dff6a87616ea27 Mon Sep 17 00:00:00 2001 From: xtomrfx Date: Thu, 30 Sep 2021 14:02:57 +0800 Subject: [PATCH 20/23] lab1guide --- .../lab1_implicit_flow_gcp/README.md" | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git "a/10 NGINX\350\256\244\350\257\201\346\216\210\346\235\203/lab1_implicit_flow_gcp/README.md" "b/10 NGINX\350\256\244\350\257\201\346\216\210\346\235\203/lab1_implicit_flow_gcp/README.md" index 9d26563..88fd70f 100644 --- "a/10 NGINX\350\256\244\350\257\201\346\216\210\346\235\203/lab1_implicit_flow_gcp/README.md" +++ "b/10 NGINX\350\256\244\350\257\201\346\216\210\346\235\203/lab1_implicit_flow_gcp/README.md" @@ -129,3 +129,14 @@ server { ![Image description](https://images.gitee.com/uploads/images/2021/0930/135746_6219bf8f_9655714.png "屏幕截图.png") +## NGINX PLUS 配置 + +1. 应用lab里的配置文件和相关资源,注意路径一致。 +2. 注意使用最新的google jwt key: + ``` + wget https://www.googleapis.com/oauth2/v3/certs -O /etc/nginx/google_certs.jwk + ``` +3. nginx plus上有两个资源, /f5demo/需要自己额外再搭一个普通web服务器即可。 /private/的资源已经上传,是一个静态图片. + +## 客户端注意事项 +1. 科学上网. \ No newline at end of file -- Gitee From 3585460455c3684145f896f12197e2924cea2bad Mon Sep 17 00:00:00 2001 From: xtomrfx Date: Thu, 30 Sep 2021 14:03:44 +0800 Subject: [PATCH 21/23] lab1guide --- .../lab1_implicit_flow_gcp/nginx.conf" | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git "a/10 NGINX\350\256\244\350\257\201\346\216\210\346\235\203/lab1_implicit_flow_gcp/nginx.conf" "b/10 NGINX\350\256\244\350\257\201\346\216\210\346\235\203/lab1_implicit_flow_gcp/nginx.conf" index 714684b..1f5ba19 100644 --- "a/10 NGINX\350\256\244\350\257\201\346\216\210\346\235\203/lab1_implicit_flow_gcp/nginx.conf" +++ "b/10 NGINX\350\256\244\350\257\201\346\216\210\346\235\203/lab1_implicit_flow_gcp/nginx.conf" @@ -26,7 +26,7 @@ http { keepalive_timeout 65; - + #自己后台搭建个web资源即可 upstream api_server { server 10.1.20.11; server 10.1.20.12; -- Gitee From cb5eabf2f9b1514894db0eeb492a27132896e1e0 Mon Sep 17 00:00:00 2001 From: xtomrfx Date: Thu, 30 Sep 2021 14:04:36 +0800 Subject: [PATCH 22/23] labguide --- .../lab2_author_code_flow_okta/README.md" | 168 ------------------ .../lab3_token_introspection_okta/README.md" | 168 ------------------ 2 files changed, 336 deletions(-) diff --git "a/10 NGINX\350\256\244\350\257\201\346\216\210\346\235\203/lab2_author_code_flow_okta/README.md" "b/10 NGINX\350\256\244\350\257\201\346\216\210\346\235\203/lab2_author_code_flow_okta/README.md" index 5484746..e69de29 100644 --- "a/10 NGINX\350\256\244\350\257\201\346\216\210\346\235\203/lab2_author_code_flow_okta/README.md" +++ "b/10 NGINX\350\256\244\350\257\201\346\216\210\346\235\203/lab2_author_code_flow_okta/README.md" @@ -1,168 +0,0 @@ -# Lab环境介绍 - -本次演示和实验采用Docker环境,学员可根据自己实际情况准备实验环境。本环境中包含以下组件: - -## NGINX Plus反向代理服务器 -后面简称反代,可通过*Dockerfile*生成容器镜像,容器暴露端口如下: -- Web服务:8080:80 -- API:8000:8000 - -容器启动后,登录容器,在/etc/nginx/conf.d/目录下创建 *api-8000.conf* ,执行 `nginx -s reload` ,在实验客户端访问 http://x.x.x.x:8080 确认可以看到NGINX欢迎页面,访问 http://x.x.x.x:8000 ,确认可以打开Dashboard。x.x.x.x为Docker服务器的IP,也即反代的IP,下同。 - -## Web Servers -后面简称Web,可直接使用和反代相同的N+镜像,不对外暴露端口,使用Docker网桥和N+反代通信 - -## 测试客户端 -请预装以下软件,并且为了方便测试,建议在客户端hosts配置测试所用域名。 -- curl -- wrk -- 浏览器 - ---- - -# 实验步骤 - -NGINX安装目录为/etc/nginx/,所有实验配置文件均保存在/etc/nginx/conf.d/目录下。 - -请修改实验客户端*hosts*文件,将实验相关域名解析到反代的IP,反代IP设定为x.x.x.x。 - -## Lab1 变量 -1. 在反代中创建 *variable.conf* 文件,执行 `nginx -s reload` ,观察配置文件是否能被加载。 - -2. 访问http://variable.will.com:8080/noset 和 http://variable.will.com:8080/set ,观察返回的页面信息。 - -3. 删除 *variable.conf* 中第4行的注释符 - ``` - set $f5 "is the best ADC!"; - ``` - 重复第1、2步。 - -4. 在 *variable.conf* 中第11行增加注释符 - ``` - #set $f5 "NGINX is a part of F5"; - ``` - 重复第1步。 - -## Lab2 蓝绿部署 -1. 在反代中创建 *bluegreen.conf* 文件,upstream *blue* 和 *green* 分别修改为Web1和Web2的容器IP,执行 `nginx -s reload`。 -2. 在实验客户端执行以下命令,观察输出,应该为空。 - ``` - curl http://x.x.x.x:8000/api/6/http/keyvals/blue-green - ``` -3. 访问 http://bluegreen.will.com:8080 ,应该访问到Web1。 -4. 在实验客户端执行以下命令。 - ``` - curl -X POST -d '{"environment": "green"} http://x.x.x.x:8000/api/6/http/keyvals/blue-green - ``` -5. 访问 http://bluegreen.will.com:8080 ,应该访问到Web2。 -6. 在实验客户端执行以下命令。 - ``` - curl -X PATCH -d '{"environment": "blue"} http://x.x.x.x:8000/api/6/http/keyvals/blue-green - ``` -7. 访问 http://bluegreen.will.com:8080 ,应该访问到Web1。 - -## Lab3 AB Test -1. 在反代中创建 *abtest.conf* 文件,upstream *abtest_a* 和 *abtest_b* 分别修改为Web1和Web2的容器IP,执行 `nginx -s reload`。 -2. 在实验客户端通过wrk打压力,参考命令 `wrk -c200 -t8 -d300s "http://abtest.will.com:8080" ,打开Dashboard,观察upstream,所有的request应该都打向abtest_a。 -3. 在实验客户端执行以下命令。 - ``` - curl -X POST -d '{"bpercentage": 5} http://x.x.x.x:8000/api/6/http/keyvals/abtest - ``` -4. 通过Dashboard,观察upstream,应该有5%左右的request打向abtest_b。 -5. 在实验客户端执行以下命令。 - ``` - curl -X PATCH -d '{"bpercentage": 20} http://x.x.x.x:8000/api/6/http/keyvals/abtest - ``` -6. 通过Dashboard,观察upstream,应该有20%左右的request打向abtest_b。 -7. 在实验客户端执行以下命令。 - ``` - curl -X PATCH -d '{"bpercentage": 50} http://x.x.x.x:8000/api/6/http/keyvals/abtest - ``` -8. 通过Dashboard,观察upstream,应该有50%左右的request打向abtest_b。 -9. 在实验客户端执行以下命令。 - ``` - curl -X PATCH -d '{"bpercentage": 100} http://x.x.x.x:8000/api/6/http/keyvals/abtest - ``` -10. 通过Dashboard,观察upstream,应该所有的request都打向abtest_b。 - -## Lab4 灰度发布 -1. 在反代中创建 *canary.conf* 文件,upstream *v1_only* 、 *v2_only* 、 *all* 分别修改为Web1和Web2的容器IP,执行 `nginx -s reload`。 -2. 在实验客户端多次用curl模拟各种浏览器访问,应该在Web1和Web2之间轮询。 - ``` - curl -A 'Chrome' http://canary.will.com:8080 - ``` -3. 在实验客户端执行以下命令。 - ``` - curl -X POST -d '{"stage": "b"} http://x.x.x.x:8000/api/6/http/keyvals/canary - ``` -4. 在实验客户端多次用curl模拟各种浏览器访问,应该只会访问到Web1。 - ``` - curl -A 'Chrome' http://canary.will.com:8080 - ``` -5. 在实验客户端执行以下命令。 - ``` - curl -X PATCH -d '{"stage": "c"} http://x.x.x.x:8000/api/6/http/keyvals/canary - ``` -6. 在实验客户端多次用curl模拟Chrome浏览器访问,应该只会访问到Web2。 - ``` - curl -A 'Chrome' http://canary.will.com:8080 - ``` -7. 在实验客户端多次用curl模拟Firefox浏览器访问,应该只会访问到Web1。 - ``` - curl -A 'Firefox' http://canary.will.com:8080 - ``` -8. 在实验客户端模拟其它浏览器访问,例如Safari,应该也只会访问到Web1。 -9. 在实验客户端执行以下命令。 - ``` - curl -X PATCH -d '{"stage": "d"} http://x.x.x.x:8000/api/6/http/keyvals/canary - ``` -10. 在实验客户端多次用curl模拟各种浏览器访问,应该只会访问到Web2。 -11. 在实验客户端执行以下命令。 - ``` - curl -X PATCH -d '{"stage": "a"} http://x.x.x.x:8000/api/6/http/keyvals/canary - ``` -12. 在实验客户端多次用curl模拟各种浏览器访问,应该在Web1和Web2之间轮询。 - -## Lab5 动态限流 -1. 在反代中创建 *ratelimit.conf* 文件,upstream *ratelimit* 分别修改为Web1和Web2的容器IP,执行 `nginx -s reload`。 -2. 在实验客户端通过wrk打压力,参考命令 `wrk -c200 -t8 -d300s "http://ratelimit.will.com:8080" ,打开Dashboard观察,此时应该是正常分发流量,没有任何限速。 -3. 在实验客户端执行以下命令,打开限速200rps的开关。 - ``` - curl -X POST -d '{"ratelimit_200": 1} http://x.x.x.x:8000/api/6/http/keyvals/kv_ratelimit - ``` -4. 打压力的同时观察Dashboard,应该被限制在了200rps左右,同时观察delay的效果。 -5. 在实验客户端执行以下命令,打开限速100rps的开关。 - ``` - curl -X POST -d '{"ratelimit_100": 1} http://x.x.x.x:8000/api/6/http/keyvals/kv_ratelimit - ``` -6. 打压力的同时观察Dashboard,应该被限制在了100rps左右,同时观察nodelay的效果。 - -## Lab6 熔断 -1. 在反代中创建 *circuitbreaker.conf* 文件,upstream *circuitbreaker* 分别修改为Web1和Web2的容器IP,执行 `nginx -s reload`。 -2. 打开Dashboard,观察健康检查的情况。 -3. 在实验客户端通过wrk打压力,参考命令 `wrk -c200 -t8 -d300s "http://circuit.will.com:8080" ,打开Dashboard观察,此时应该是正常分发流量。 -4. 登录Web2容器,修改 */etc/nginx/conf.d/default.conf* 文件,将以下部分中return的值做任意改变,执行 `nginx -s reload`。 - ``` - location /health { - default_type application/json; - return 200 '{"deadlocks":{"healthy":true},"Disk":{"healthy":false},"Memory":{"healthy":true}}'; - } - ``` -5. 观察Dashboard,Web2应该被健康检查标记为down,流量全部打向Web1。 -6. 登录Web2容器,将 */etc/nginx/conf.d/default.conf* 文件修改为正常值,执行 `nginx -s reload`。 - ``` - location /health { - default_type application/json; - return 200 '{"deadlocks":{"healthy":true},"Disk":{"healthy":true},"Memory":{"healthy":true}}'; - } - ``` -7. 观察Dashboard,Web2连续三次健康检查通过后应该被重新标记为up,并且开始逐步接收流量,最终和Web1达到1:1。 -8. 删除反代 *circuitbreaker.conf* 文件中的slow_start参数,执行 `nginx -s reload`。 - ``` - upstream circuitbreaker { - server 172.17.0.3:80; - server 172.17.0.4:80; - zone circuitbreaker 64k; - } - ``` -9. 重复4至7步,观察没有slow_start时候的效果。 diff --git "a/10 NGINX\350\256\244\350\257\201\346\216\210\346\235\203/lab3_token_introspection_okta/README.md" "b/10 NGINX\350\256\244\350\257\201\346\216\210\346\235\203/lab3_token_introspection_okta/README.md" index 5484746..e69de29 100644 --- "a/10 NGINX\350\256\244\350\257\201\346\216\210\346\235\203/lab3_token_introspection_okta/README.md" +++ "b/10 NGINX\350\256\244\350\257\201\346\216\210\346\235\203/lab3_token_introspection_okta/README.md" @@ -1,168 +0,0 @@ -# Lab环境介绍 - -本次演示和实验采用Docker环境,学员可根据自己实际情况准备实验环境。本环境中包含以下组件: - -## NGINX Plus反向代理服务器 -后面简称反代,可通过*Dockerfile*生成容器镜像,容器暴露端口如下: -- Web服务:8080:80 -- API:8000:8000 - -容器启动后,登录容器,在/etc/nginx/conf.d/目录下创建 *api-8000.conf* ,执行 `nginx -s reload` ,在实验客户端访问 http://x.x.x.x:8080 确认可以看到NGINX欢迎页面,访问 http://x.x.x.x:8000 ,确认可以打开Dashboard。x.x.x.x为Docker服务器的IP,也即反代的IP,下同。 - -## Web Servers -后面简称Web,可直接使用和反代相同的N+镜像,不对外暴露端口,使用Docker网桥和N+反代通信 - -## 测试客户端 -请预装以下软件,并且为了方便测试,建议在客户端hosts配置测试所用域名。 -- curl -- wrk -- 浏览器 - ---- - -# 实验步骤 - -NGINX安装目录为/etc/nginx/,所有实验配置文件均保存在/etc/nginx/conf.d/目录下。 - -请修改实验客户端*hosts*文件,将实验相关域名解析到反代的IP,反代IP设定为x.x.x.x。 - -## Lab1 变量 -1. 在反代中创建 *variable.conf* 文件,执行 `nginx -s reload` ,观察配置文件是否能被加载。 - -2. 访问http://variable.will.com:8080/noset 和 http://variable.will.com:8080/set ,观察返回的页面信息。 - -3. 删除 *variable.conf* 中第4行的注释符 - ``` - set $f5 "is the best ADC!"; - ``` - 重复第1、2步。 - -4. 在 *variable.conf* 中第11行增加注释符 - ``` - #set $f5 "NGINX is a part of F5"; - ``` - 重复第1步。 - -## Lab2 蓝绿部署 -1. 在反代中创建 *bluegreen.conf* 文件,upstream *blue* 和 *green* 分别修改为Web1和Web2的容器IP,执行 `nginx -s reload`。 -2. 在实验客户端执行以下命令,观察输出,应该为空。 - ``` - curl http://x.x.x.x:8000/api/6/http/keyvals/blue-green - ``` -3. 访问 http://bluegreen.will.com:8080 ,应该访问到Web1。 -4. 在实验客户端执行以下命令。 - ``` - curl -X POST -d '{"environment": "green"} http://x.x.x.x:8000/api/6/http/keyvals/blue-green - ``` -5. 访问 http://bluegreen.will.com:8080 ,应该访问到Web2。 -6. 在实验客户端执行以下命令。 - ``` - curl -X PATCH -d '{"environment": "blue"} http://x.x.x.x:8000/api/6/http/keyvals/blue-green - ``` -7. 访问 http://bluegreen.will.com:8080 ,应该访问到Web1。 - -## Lab3 AB Test -1. 在反代中创建 *abtest.conf* 文件,upstream *abtest_a* 和 *abtest_b* 分别修改为Web1和Web2的容器IP,执行 `nginx -s reload`。 -2. 在实验客户端通过wrk打压力,参考命令 `wrk -c200 -t8 -d300s "http://abtest.will.com:8080" ,打开Dashboard,观察upstream,所有的request应该都打向abtest_a。 -3. 在实验客户端执行以下命令。 - ``` - curl -X POST -d '{"bpercentage": 5} http://x.x.x.x:8000/api/6/http/keyvals/abtest - ``` -4. 通过Dashboard,观察upstream,应该有5%左右的request打向abtest_b。 -5. 在实验客户端执行以下命令。 - ``` - curl -X PATCH -d '{"bpercentage": 20} http://x.x.x.x:8000/api/6/http/keyvals/abtest - ``` -6. 通过Dashboard,观察upstream,应该有20%左右的request打向abtest_b。 -7. 在实验客户端执行以下命令。 - ``` - curl -X PATCH -d '{"bpercentage": 50} http://x.x.x.x:8000/api/6/http/keyvals/abtest - ``` -8. 通过Dashboard,观察upstream,应该有50%左右的request打向abtest_b。 -9. 在实验客户端执行以下命令。 - ``` - curl -X PATCH -d '{"bpercentage": 100} http://x.x.x.x:8000/api/6/http/keyvals/abtest - ``` -10. 通过Dashboard,观察upstream,应该所有的request都打向abtest_b。 - -## Lab4 灰度发布 -1. 在反代中创建 *canary.conf* 文件,upstream *v1_only* 、 *v2_only* 、 *all* 分别修改为Web1和Web2的容器IP,执行 `nginx -s reload`。 -2. 在实验客户端多次用curl模拟各种浏览器访问,应该在Web1和Web2之间轮询。 - ``` - curl -A 'Chrome' http://canary.will.com:8080 - ``` -3. 在实验客户端执行以下命令。 - ``` - curl -X POST -d '{"stage": "b"} http://x.x.x.x:8000/api/6/http/keyvals/canary - ``` -4. 在实验客户端多次用curl模拟各种浏览器访问,应该只会访问到Web1。 - ``` - curl -A 'Chrome' http://canary.will.com:8080 - ``` -5. 在实验客户端执行以下命令。 - ``` - curl -X PATCH -d '{"stage": "c"} http://x.x.x.x:8000/api/6/http/keyvals/canary - ``` -6. 在实验客户端多次用curl模拟Chrome浏览器访问,应该只会访问到Web2。 - ``` - curl -A 'Chrome' http://canary.will.com:8080 - ``` -7. 在实验客户端多次用curl模拟Firefox浏览器访问,应该只会访问到Web1。 - ``` - curl -A 'Firefox' http://canary.will.com:8080 - ``` -8. 在实验客户端模拟其它浏览器访问,例如Safari,应该也只会访问到Web1。 -9. 在实验客户端执行以下命令。 - ``` - curl -X PATCH -d '{"stage": "d"} http://x.x.x.x:8000/api/6/http/keyvals/canary - ``` -10. 在实验客户端多次用curl模拟各种浏览器访问,应该只会访问到Web2。 -11. 在实验客户端执行以下命令。 - ``` - curl -X PATCH -d '{"stage": "a"} http://x.x.x.x:8000/api/6/http/keyvals/canary - ``` -12. 在实验客户端多次用curl模拟各种浏览器访问,应该在Web1和Web2之间轮询。 - -## Lab5 动态限流 -1. 在反代中创建 *ratelimit.conf* 文件,upstream *ratelimit* 分别修改为Web1和Web2的容器IP,执行 `nginx -s reload`。 -2. 在实验客户端通过wrk打压力,参考命令 `wrk -c200 -t8 -d300s "http://ratelimit.will.com:8080" ,打开Dashboard观察,此时应该是正常分发流量,没有任何限速。 -3. 在实验客户端执行以下命令,打开限速200rps的开关。 - ``` - curl -X POST -d '{"ratelimit_200": 1} http://x.x.x.x:8000/api/6/http/keyvals/kv_ratelimit - ``` -4. 打压力的同时观察Dashboard,应该被限制在了200rps左右,同时观察delay的效果。 -5. 在实验客户端执行以下命令,打开限速100rps的开关。 - ``` - curl -X POST -d '{"ratelimit_100": 1} http://x.x.x.x:8000/api/6/http/keyvals/kv_ratelimit - ``` -6. 打压力的同时观察Dashboard,应该被限制在了100rps左右,同时观察nodelay的效果。 - -## Lab6 熔断 -1. 在反代中创建 *circuitbreaker.conf* 文件,upstream *circuitbreaker* 分别修改为Web1和Web2的容器IP,执行 `nginx -s reload`。 -2. 打开Dashboard,观察健康检查的情况。 -3. 在实验客户端通过wrk打压力,参考命令 `wrk -c200 -t8 -d300s "http://circuit.will.com:8080" ,打开Dashboard观察,此时应该是正常分发流量。 -4. 登录Web2容器,修改 */etc/nginx/conf.d/default.conf* 文件,将以下部分中return的值做任意改变,执行 `nginx -s reload`。 - ``` - location /health { - default_type application/json; - return 200 '{"deadlocks":{"healthy":true},"Disk":{"healthy":false},"Memory":{"healthy":true}}'; - } - ``` -5. 观察Dashboard,Web2应该被健康检查标记为down,流量全部打向Web1。 -6. 登录Web2容器,将 */etc/nginx/conf.d/default.conf* 文件修改为正常值,执行 `nginx -s reload`。 - ``` - location /health { - default_type application/json; - return 200 '{"deadlocks":{"healthy":true},"Disk":{"healthy":true},"Memory":{"healthy":true}}'; - } - ``` -7. 观察Dashboard,Web2连续三次健康检查通过后应该被重新标记为up,并且开始逐步接收流量,最终和Web1达到1:1。 -8. 删除反代 *circuitbreaker.conf* 文件中的slow_start参数,执行 `nginx -s reload`。 - ``` - upstream circuitbreaker { - server 172.17.0.3:80; - server 172.17.0.4:80; - zone circuitbreaker 64k; - } - ``` -9. 重复4至7步,观察没有slow_start时候的效果。 -- Gitee From c65de9fa183ad3bf08082fdf62a6583a1a52af47 Mon Sep 17 00:00:00 2001 From: xtomrfx Date: Thu, 30 Sep 2021 14:11:12 +0800 Subject: [PATCH 23/23] lab1guide --- .../lab1_implicit_flow_gcp/README.md" | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git "a/10 NGINX\350\256\244\350\257\201\346\216\210\346\235\203/lab1_implicit_flow_gcp/README.md" "b/10 NGINX\350\256\244\350\257\201\346\216\210\346\235\203/lab1_implicit_flow_gcp/README.md" index 88fd70f..1eb3212 100644 --- "a/10 NGINX\350\256\244\350\257\201\346\216\210\346\235\203/lab1_implicit_flow_gcp/README.md" +++ "b/10 NGINX\350\256\244\350\257\201\346\216\210\346\235\203/lab1_implicit_flow_gcp/README.md" @@ -139,4 +139,4 @@ server { 3. nginx plus上有两个资源, /f5demo/需要自己额外再搭一个普通web服务器即可。 /private/的资源已经上传,是一个静态图片. ## 客户端注意事项 -1. 科学上网. \ No newline at end of file +1. 注意因为google无法访问,需要额外处理。 \ No newline at end of file -- Gitee