http_proxyの挙動確認


はじめに

localhostへの通信さえもプロキシサーバを通るように設定できると聞いたので、実験。

環境

  • Ubuntu18.04
  • bash

実験

proxy設定前

$ curl http://google.com
<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>301 Moved</TITLE></HEAD><BODY>
<H1>301 Moved</H1>
The document has moved
<A HREF="http://www.google.com/">here</A>.
</BODY></HTML>

proxy設定後

1行目でproxyの設定をしている。

実際にはプロキシサーバを立ててないので localhost:9999 に繋げないが、プロキシサーバに繋ごうとしているのが分かる。

$ export http_proxy=localhost:9999
$ curl http://google.com
curl: (7) Failed to connect to localhost port 9999: Connection refused

proxyを通らないホストを指定

1行目でproxyを通らないホストを指定している。

プロキシサーバを通らずにhttpアクセスできた。

$ export no_proxy=google.com
$ curl http://google.com
<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>301 Moved</TITLE></HEAD><BODY>
<H1>301 Moved</H1>
The document has moved
<A HREF="http://www.google.com/">here</A>.
</BODY></HTML>

おわりに

プロキシの設定について少し賢くなった。