(1)、使用if指令实现upstreamserver_01{server192.168.1.100:8080max_fails=1fail_timeout=60;}upstreamserver_02{server192.168.1.101:8080max_fails=1fail_timeout=60;}server{listen80;server_namewww.server.com;#matchcookieset$server"server_01";if($http_cookie~*"version=V1"){set$serverserver_01;}if($http_cookie~*"version=V2"){set$serverserver_02;}location/{proxy_passhttp://$server;proxy_set_headerHost$host;proxy_set_headerX-Real-IP$remote_addr;proxy_set_headerX-Forwarded-For$proxy_add_x_forwarded_for;indexindex.htmlindex.htm;}}(2)、使用map指令实现upstreamserver_01{server192.168.1.100:8080max_fails=1fail_timeout=60;}upstreamserver_02{server192.168.1.101:8080max_fails=1fail_timeout=60;}map$COOKIE_version$server{~*V1$server_01;~*V2$server_02;defaultserver_01;}server{listen80;server_namewww.server.com;location/{proxy_passhttp://$server;proxy_set_headerHost$host;proxy_set_headerX-Real-IP$remote_addr;proxy_set_headerX-Forwarded-For$proxy_add_x_forwarded_for;indexindex.htmlindex.htm;}}2、根据权重实现灰度配置upstreamserver{server192.168.1.100:8080max_fails=1fail_timeout=60weight=5;server192.168.1.101:8080max_fails=1fail_timeout=60weight=1;}server{listen80;server_namewww.server.com;location/{proxy_passhttp://server;proxy_set_headerHost$host;proxy_set_headerX-Real-IP$remote_addr;proxy_set_headerX-Forwarded-For$proxy_add_x_forwarded_for;indexindex.htmlindex.htm;}}3、根据来路IP实现灰度配置(1)、资源在不同服务器上upstreamserver_01{server192.168.1.100:8080max_fails=1fail_timeout=60;}upstreamserver_02{server192.168.1.101:8080max_fails=1fail_timeout=60;}server{listen80;server_namewww.server.com;set$server"server_01";if($remote_addr~"211.118.119.11"){set$serverserver_02;}location/{proxy_passhttp://$server;proxy_set_headerHost$host;proxy_set_headerX-Real-IP$remote_addr;proxy_set_headerX-Forwarded-For$proxy_add_x_forwarded_for;indexindex.htmlindex.htm;}}(2)、资源在同一服务器上server{listen80;server_namewww.server.com;set$rootdir"/var/www/html";if($remote_addr~"211.118.119.11"){set$rootdir"/var/www/test";}location/{root$rootdir;proxy_set_headerHost$host;proxy_set_headerX-Real-IP$remote_addr;proxy_set_headerX-Forwarded-For$proxy_add_x_forwarded_for;indexindex.htmlindex.htm;}}4、Nginx+Lua实现灰度配置#如果来源IP地址是ipList.conf中的地址 , 那么就定位到test_env , 如果来源IP地址不在ipList.conf中(即有效用户IP) , 那么就定位到product_env 。 localip_config=ngx.shared.config;ClienIP=ngx.req.get_headers()["X-Real-IP"]ifClientIP==nilthenClientIP=ngx.req.get_headers()["x_forworded_for"]endifClientIP==nilthenClientIP=ngx.var.remote_addrendforlineinio.lines("/usr/local/nginx/conf/lua/ipList.conf")doifnotip_config:get(line)thenip_config:set(line,"0")endendifip_config:get(ClientIP)=="0"thenngx.exec("@test_env")elsengx.exec("@product_env")endipList.conf内容格式XXX.XXX.XXX.XXXYYY.YYY.YYY.YYYlua_code_cacheon;lua_shared_dictconfig1m;upstreamMyServer{server192.168.1.199:8099max_fails=3fail_timeout=30s;server192.168.1.200:8099max_fails=3fail_timeout=30s;ip_hash;}server{listen80;server_namejokerzhang.cn;access_logoff;#access_loglogs/jokerzhang.log;location/{access_by_lua_file/usr/local/nginx/conf/lua/ip_gray.lua;}location@test_env{proxy_pass;proxy_set_headerHost$host;proxy_set_headerX-Real-IP$remote_addr;proxy_set_headerX-Forwarded-For$proxy_add_x_forwarded_for;}location@product_env{proxy_passhttp://MyServer;proxy_set_headerHost$host;proxy_set_headerX-Real-IP$remote_addr;proxy_set_headerX-Forwarded-For$proxy_add_x_forwarded_for;}}作者:Fantasy
推荐阅读
-
-
漫漫笑:别到时候钱没留下,孩子留了一堆,搞笑段子:哼哼
-
-
辰雪丰华|穿一字肩礼服出镜,P掉小肚子更甜美,陈乔恩被说“胖”了的美照
-
科普成华 测谎仪都拿他没办法,如今却销声匿迹!,火星男孩预言2020年大灾难
-
好身材|小姐姐一条蓝色紧身牛仔裤,展示出不一样的魅力
-
淼淼|2岁女童10分钟横渡两百米沾天湖 网友自嘲:自己20多岁还游不了1米
-
-
[台安]《GTA5》最无聊的实验有哪些?家里买了台安检机,是否有效?
-
【大众网】四喜儿“不讨喜”引热议,孙迪《鬓边不是海棠红》上线
-
德怀特·霍华德|放弃霍华德!湖人为何签下哈勒尔?三方面解读,得分能力更加出色
-
格尔木通报女大学生失联:今晨救援力量已赴可可西里查找
-
东京奥运会|东京奥运会定于2021年7月23日开幕,场馆和赛程已确认
-
5G|运营商宽带提速到500兆,为什么网速没变化?是谁偷了我的带宽?
-
可爱的小冉就不会有我的今天,克罗斯:如果没有海因克斯
-
女人梦见上面的牙掉了一颗 梦见上面的牙掉了一颗还有血
-
数学▲?2020年高考数学难吗?学生:不怎么难就是有点懵圈
-
北京日报客户端|调查称仅9%为无症状感染者,巴西新冠肺炎累计确诊人数近150万
-
-
「自摆乌龙」山西一球队后卫自摆乌龙被门将杀害?警方回应