
前提:只听过没用过,对 nginx 有基础认识
现在想做基于代码分支的测试环境自动化管理,具体而言:
upstream hilinux_01 { server 192.168.1.100:8080 max_fails=1 fail_timeout=60; } upstream hilinux_02 { server 192.168.1.200:8080 max_fails=1 fail_timeout=60; } upstream default { server 192.168.1.100:8080 max_fails=1 fail_timeout=60; } server { listen 80; server_name www.hi-linux.com; access_log logs/www.hi-linux.com.log main; #match cookie set $group "default"; if ($http_cookie ~* "version=V1"){ set $group hilinux_01; } if ($http_cookie ~* "version=V2"){ set $group hilinux_02; } location / { proxy_pass http://$group; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; index index.html index.htm; } } 有新的分支部署时需要修改 nginx 配置,openresty 可以根据 cookie 的 value 去 redis 中取出匹配的 ip:port 作为反向代理的目标机器吗?有没有相关资料或者案例可以模仿呢?
1 hingbong 2021-11-30 14:47:27 +08:00 不用 lua 没试过,我们逻辑都是写在 lua 里 https://github.com/openresty/lua-resty-redis https://github.com/cloudflare/lua-resty-cookie 用这两个应该就很容易实现了 |
2 superhack 2021-11-30 14:47:37 +08:00 可以。能写 lua 代码,什么都能控制。 |
3 NsLib 2021-11-30 14:53:46 +08:00 可以,这就是一个简单的泳道,可以去搜一下这个概念。 |
4 dnsjia 2021-11-30 16:53:05 +08:00 |
5 ffdshow233 2021-12-15 13:27:39 +08:00 via Android 用 lua ,可以写 |