File tree Expand file tree Collapse file tree 2 files changed +19
-4
lines changed
Expand file tree Collapse file tree 2 files changed +19
-4
lines changed Original file line number Diff line number Diff line change @@ -106,12 +106,26 @@ Flags:
106106经过` mars ` 的流量可在web页查看
107107
108108### Nginx
109- 请求包含特定header, 则转发给` mars `
110- ``` ini
111- proxy_set_header X-Mars-Debug 0;
112- proxy_set_header Host $http_host;
109+ 请求包含特定header, 则转发给` mars ` , 由` mars ` 访问实际的后端
110+
111+ 原配置
112+ ``` nginx
113+ proxy_pass http://172.16.10.103:8080;
114+ ```
115+
116+ 使用` mars ` 后的配置
117+ ``` nginx
118+ set $targetHost $host;
119+
120+ if ($http_x_mars_debug = "1") {
121+ set $targetHost "172.16.10.103:8080";
122+ }
123+
124+ proxy_set_header X-Mars-Host $host;
125+ proxy_set_header Host $targetHost;
113126 if ($http_x_mars_debug = "1") {
114127 proxy_pass http://localhost:8888;
128+ break;
115129 }
116130```
117131
Original file line number Diff line number Diff line change @@ -88,6 +88,7 @@ func (r *Recorder) BeforeRequest(ctx *goproxy.Context) {
8888 if host := ctx .Req .Header .Get ("X-Mars-Host" ); host != "" {
8989 ctx .Req .Host = host
9090 }
91+ ctx .Req .Header .Del ("X-Mars-Host" )
9192 ctx .Req .Header .Del ("X-Mars-Debug" )
9293 if r .interceptor != nil {
9394 r .interceptor .BeforeRequest (ctx )
You can’t perform that action at this time.
0 commit comments