1.グレースケールリリーストポロジマップ、会社のローカルアクセスサービスがグレースケール環境に入り、他のアクセスが元々生成されます。
2. nginx.confの設定
[root @ VM_0_7_centos conf]#cat nginx.conf worker_processes 1 ; error_logログ / error.log; イベント{ worker_connections 1024 ; } http { include vhost / * .conf; サーバー{ 待機22222; server_name 10.0.0.7 www.a.com localhost; #charset koi8-r; #access_log logs / host.access.log main; default_type 'text / plain'; 場所/ test { content_by_lua_file /Users/chenguowei/local/openresty/nginx/lua_conf/huidu.lua; } 場所@ client1 { proxy_passhttp:// client1 ; } 場所@ client2 { proxy_pass http:// client2 ; } } }
3.nginxのluginスクリプト
ソースIPがmyipの場合はグレースケールに入り、もう1つは本番環境に入ります。
[root @ VM_0_7_centos〜]#cat / Users / chenguowei / local / openresty / nginx / lua_conf / huidu.lua local redis = require " resty.redis " local cache = redis。新しい() SET_TIMEOUT(:キャッシュ60000 ) ローカルOK、ERR = cache.connect(キャッシュ、" 10.0.0.205 "、6379 ) の場合ではないOK、その後 (ngx.say " :Redisの接続に失敗しました" 、ERR) リターン 終了 ローカルlocal_ipを = ngx.req.get_headers()[ " X-Real-IP " ] if== local_ipをその後、nilを local_ipを = ngx.req.get_headers()[ " x_forwarded_for " ] エンド IF local_ipを== その後、nilを local_ipを。= NGXは、VAR .remote_addr エンド ローカルインターセプト =キャッシュ:GET("MYIP " ) IFインターセプト== local_ipを次に ngx.exec(" @ client2 " ) return end ngx.exec(" @ client1 ")- 以前はngx.say()関数を実行できません。それ以外の場合、リクエストは ローカルok、err= cache:close() 正常でない場合、ngx.say("のクローズに失敗しました:" 、err) return end
4. redisがIPを設定
[root @ VM_0_42_centos src]#. /redis-cli -h 10.0。0.205 -p 6379 10.0。0.205:6379 > set myip 10.0。0.7 OK 10.0。0.205:6379 >
リファレンス:https : //blog.csdn.net/gochenguowei/article/details/85041578