nginx mirror/post_action+gor實現https流量復制


個人學習筆記,謝絕轉載!!!

原文:https://www.cnblogs.com/wshenjin/p/11850386.html


關於gor:

參考:

https://www.cnblogs.com/jinjiangongzuoshi/p/11773070.html

https://github.com/buger/goreplay/wiki/Getting-Started

這篇小記主要是記錄gor不支持https流量鏡像的一種解決思路

https流量鏡像

1、在nginx proxy 配置 post_action(或者mirror),實現https流量鏡像出http流量到gor

server
{
      listen       80;
      listen       443;
      server_name  tt.example.com;
      index index.html index.php;
      root  /data/web/webclose;
      location / {
            expires off;
            proxy_redirect     off;
            proxy_set_header   Host             tt.example.com;
            proxy_set_header   X-Real-IP        $remote_addr;
            proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
            proxy_pass https://1.1.1.1:443;
            #配置post_action
            post_action @tt_http;
            #或者配置mirror
            mirror /mirror;
            mirror_request_body on;     #指定是否鏡像請求body部分,此選項與proxy_request_buffering、fastcgi_request_buffering、scgi_request_buffering和 uwsgi_request_buffering沖突,一旦開啟mirror_request_body,則請求自動緩存;
      }
      #mirror
      location /mirror {
            internal;              #指定此location只能被“內部的”請求調用,外部的調用請求會返回”Not found” (404)
            proxy_redirect     off;
            proxy_set_header   Host             tt.example.com;
            proxy_set_header   X-Real-IP        $remote_addr;
            proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
            proxy_pass http://1.1.1.2:8080$request_uri;       #原始uri不會鏡像,可以通過$request_uri變量取得原始請求的uri
            proxy_set_header X-Original-URI $request_uri;
      }
      #post_action
      location @tt_http {
            expires off;
            proxy_redirect     off;
            proxy_set_header   Host             tt.example.com;
            proxy_set_header   X-Real-IP        $remote_addr;
            proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
            proxy_pass http://1.1.1.2:8080;
      }
      include deny_file.conf;
      include ssl.conf;
      access_log  /data/logs/$host.log  access;
}

2、在1.1.1.2上啟動gor 監聽8080端口,並將http流量輸出到文件

./gor --http-pprof :8080  --input-raw :8080  --input-raw-realip-header "X-Real-IP"  --output-file /tmp/goreplay/requests.gor

ps: 輸出的文件似乎是被切割的?requests_0.gor、requests_1.gor、requests_2.gor ....

3、利用gor導出的文件,對測試環境進行模擬請求

./gor --input-file /tmp/goreplay/requests_1.gor --output-http="http://t0.example.com" 

從測試上看,go_action和mirror的區別在於:

  1. go_action會等待真實的請求完成,再進行鏡像請求,而這個等待過程不影響ngx worker進程接受處理其他的請求
  2. mirror,向后端發送真實的請求后,不會等待結果而是直接開始鏡像請求


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM