GitをProxy環境下で使うときにハマった件

Gitを社内(Proxy環境下)で使うときは気をつけましょう

  • Atlassian Stashのサーバ構築も終わり、試しに使いながらSubversionから移行をしていたら早速ハマった。

いきなりClone出来ない

  • Stashでリポジトリを作成し、画面からCloneするとSourceTreeが上がるのだが、エラーでClone出来ない。
    • 以下のようなエラーが出る。

fatal: unable to access 'http://git.example.com/scm/test/test/': The requested URL returned error: 503

デバッグしてみた

  • SourceTreeはGitコマンドを呼んでるだけのようなので分かりやすくコマンドを叩いてデバッグしてみた。

$ git clone http://git.example.com/scm/test/test
Cloning into 'test'...
fatal: unable to access 'http://git.example.com/scm/test/test/': The requested URL returned error: 503

$ export GIT_CURL_VERBOSE=1
$ git clone http://git.example.com/scm/test/test
Cloning into 'test'...
* Couldn't find host git.example.com in the .netrc file; using defaults
* Adding handle: conn: 0x7f85c9011800
* Adding handle: send: 0
* Adding handle: recv: 0
* Curl_addHandleToPipeline: length: 1
* - Conn 0 (0x7f85c9011800) send_pipe: 1, recv_pipe: 0
* About to connect() to proxy proxy.example.com port 8080 (#0)
*   Trying 192.168.0.xxx...
* Connected to proxy.example.com (192.168.0.xxx) port 8080 (#0)
> GET http://git.example.com/scm/test/test/info/refs?service=git-upload-pack HTTP/1.1
User-Agent: git/1.8.5.2 (Apple Git-48)
Host: git.example.com
Accept: */*
Accept-Encoding: gzip
Proxy-Connection: Keep-Alive
Pragma: no-cache

* HTTP 1.0, assume close after body
< HTTP/1.0 503 Service Unavailable
< Content-Type: text/html; charset=UTF-8
< Cache-Control: no-cache
<
* Closing connection 0
fatal: unable to access 'http://git.example.com/scm/test/test/': The requested URL returned error: 503
  • どうやらプロキシ経由で接続に行っていることがわかった。
    • そういえば、環境変数HTTP_PROXYHTTPS_PROXYを設定してたな。
    • うちのプロキシはローカルアドレスへのアクセスを拒否するのでそれでダメなんだな。
    • プロキシを経由しない除外設定をすればよいのだろうが、Gitは除外設定が効かないんじゃなかったかなー。
    • まあ、試しにNO_PROXYを設定してみよう!

$ export no_proxy=git.example.com
$ git clone http://git.example.com/scm/test/test
Cloning into 'test'...
* Couldn't find host git.example.com in the .netrc file; using defaults
* Adding handle: conn: 0x7ff729811800
* Adding handle: send: 0
* Adding handle: recv: 0
* Curl_addHandleToPipeline: length: 1
* - Conn 0 (0x7ff729811800) send_pipe: 1, recv_pipe: 0
* About to connect() to git.example.com port 80 (#0)
*   Trying 192.168.0.yyy...
* Connected to git.example.com (192.168.0.yyy) port 80 (#0)
> GET /scm/test/test/info/refs?service=git-upload-pack HTTP/1.1
User-Agent: git/1.8.5.2 (Apple Git-48)
Host: git.example.com
Accept: */*
Accept-Encoding: gzip
Pragma: no-cache

< HTTP/1.1 200 OK
* Server nginx/1.4.6 (Ubuntu) is not blacklisted
< Server: nginx/1.4.6 (Ubuntu)
< Date: Fri, 06 Jun 2014 10:26:13 GMT
< Content-Type: application/x-git-upload-pack-advertisement
< Content-Length: 310
< Connection: keep-alive
< X-AREQUESTID: 1166x5372x0
< X-XSS-Protection: 1; mode=block
< X-Frame-Options: SAMEORIGIN
< X-Content-Type-Options: nosniff
< Expires: Fri, 01 Jan 1980 00:00:00 GMT
< Pragma: no-cache
< Cache-Control: no-cache, max-age=0, must-revalidate
<
* Connection #0 to host git.example.com left intact
* Couldn't find host git.example.com in the .netrc file; using defaults
* Adding handle: conn: 0x7ff72b80aa00
* Adding handle: send: 0
* Adding handle: recv: 0
* Curl_addHandleToPipeline: length: 1
* - Conn 1 (0x7ff72b80aa00) send_pipe: 1, recv_pipe: 0
* About to connect() to git.example.com port 80 (#1)
*   Trying 192.168.0.yyy...
* Connected to git.example.com (192.168.0.yyy) port 80 (#1)
> POST /scm/test/test/git-upload-pack HTTP/1.1
User-Agent: git/1.8.5.2 (Apple Git-48)
Host: git.example.com
Accept-Encoding: gzip
Content-Type: application/x-git-upload-pack-request
Accept: application/x-git-upload-pack-result
Content-Length: 207

* upload completely sent off: 207 out of 207 bytes
< HTTP/1.1 200 OK
* Server nginx/1.4.6 (Ubuntu) is not blacklisted
< Server: nginx/1.4.6 (Ubuntu)
< Date: Fri, 06 Jun 2014 10:26:13 GMT
< Content-Type: application/x-git-upload-pack-result
< Transfer-Encoding: chunked
< Connection: keep-alive
< X-AREQUESTID: 1166x5373x0
< X-XSS-Protection: 1; mode=block
< X-Frame-Options: SAMEORIGIN
< X-Content-Type-Options: nosniff
<
* Connection #1 to host git.example.com left intact
remote: Counting objects: 10, done.
remote: Compressing objects: 100% (5/5), done.
remote: Total 10 (delta 1), reused 0 (delta 0)
Unpacking objects: 100% (10/10), done.
Checking connectivity... done.
  • こいつ、動くぞ!
    • あれ?いつの間にか出来るようになったのかな?前はたしかにダメだった気がしたんだが・・・。

よかったー。
しかし、このプロキシは私の時間とモチベーションをいつも奪っていくな。

追記

  • 最近はこのやり方だとダメっぽいので、新しいやり方に替えました。 gozuk16.hatenablog.com