通过URL参数select正确的反向代理

从我对git的理解来看,http / https界面很简单。 你有两个命令 – 推送和获取。

基于wireshark跟踪,抓取url显示为以下格式:

/git/#path-to-repo#/info/refs?service=git-upload-pack 

推送url显示为以下格式:

 /git/#path-to-repo#/info/refs?service=git-receive-pack /git/#path-to-repo#/git-receive-pack 

我想设置nginxconfiguration,以便推到一个git后端,并从另一个(git镜像使用gitblit联合)提取。

所以我build立了一个像这样的nginxconfiguration:

 proxy_cache_bypass $arg_preview; location ~ (.*)git-receive-pack { proxy_pass http://#push-ip#:8080; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-Proto http; proxy_set_header X-Forwarded-Port 80; } location / { proxy_pass http://#pull-ip#:8080/; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-Proto http; proxy_set_header X-Forwarded-Port 80; } 

/ git /#path-to-repo#/ git-receive-pack格式URL到推送IP,/ git /#path-to-repo#/ info / refs?service = git-receive-打包格式的URL仍然去拉IP。

我怎么能得到的forms/ git /#path回购#/ info / refs?服务= git-receive-pack的URL到#push-ip#也是如此?

好的,这比我想象的要容易得多。 刚刚在第一个和第二个位置块之间添加了另一个部分:

 location ~ (.*)\/refs { proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-Proto http; proxy_set_header X-Forwarded-Port 80; if ($arg_service = "git-receive-pack") { proxy_pass http://#push-ip#:8080; break; } proxy_pass http://#pull-ip#:8080; }