LoginSignup
3
3

More than 5 years have passed since last update.

EC2上にプライベートプロキシサーバを構築する

Last updated at Posted at 2015-06-29
osx$ 手元の端末のプロンプト
ec2$ EC2インスタンスのプロンプト

プロキシサーバのセットアップ

EC2インスタンスに接続します。OSは何でも良いですが、今回は Amazon Linux を使います。

osx$ ssh ec2-user@ec2-X-X-X-X.ap-northeast-1.compute.amazonaws.com

プロキシサーバとして tinyproxy をインストールします。

ec2$ sudo yum --enablerepo=epel install tinyproxy

後ほど SSH でトンネリングして使うので、listen させるのは localhost のみでOK。

ec2$ sudo sed -ie 's/#Listen 192.168.0.1/Listen 127.0.0.1/g' /etc/tinyproxy/tinyproxy.conf

自動起動させておく場合は以下を実行しておきましょう。

ec2$ sudo chkconfig tinyproxy on

起動

プロキシサーバを起動します。

ec2$ sudo service tinyproxy start

起動したら、意図したポートを listen しているか確認しましょう。

ec2$ ss -ln|grep 8888
tcp    LISTEN     0      128            127.0.0.1:8888                  *:*

トンネリング

SSHでトンネルを掘ります。手元でバインドするポートは何でも良いですが、今回は 9999 を使います。

osx$ ssh -N -L 9999:localhost:8888 ec2-user@ec2-X-X-X-X.ap-northeast-1.compute.amazonaws.com

動作確認

例えば以下のようにして外から見えるIPアドレスを確認し、EC2のアドレスが返って来れば成功です。

osx$ curl --proxy localhost:9999 ipv4.wtfismyip.com/text
X.X.X.X
3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3