2008年1月3日木曜日

ヤリイカ=squid

Rubyによるプロキシサーバで認証をつけることができなかったのであきらめました(ぉぃ

というのでUNIX系のOSで動く
squid(ヤリイカ) というものを使ってみました。
squidはヤリイカ,対潜水艦砲


まずはLinuxのインストール。
ScientificLinux(x64版,以下SL)を仮想マシン(
VMWare)にインストールしました。

まずSLのx64版のDVDイメージをダウンロードして、
仮想CDドライブにマウントしておきます。
次にVMWare1.0.4Server(Win)のウィザードに従ってLinuxのインストールをします。




図1. □をクリックして仮想マシンを作成



終わったら仮想マシンを起動、 Linuxのインストールが始まります。
仮想マシン祈祷中…
Now Installing...
※LinuxのインストールについてはGoogle先生に情報の提供を依頼してください。

インストールが完了したら早速ヤリイカ(squid)の設定に入ります。



/etc/squid/squid.conf
基本的にこのファイルに対して設定を記述します。
ここでは基本的なことしか書きません。認証(digest認証)程度です。キャッシュについてなんかはGoogle先生に…
難しいのはいや〜(ぉぃ

設定

http_port 3128 #実験なのでどこでもよし

#認証について
#デフォルトの設定でコメントになっていたものを流用(#を外す設定)

#x64版ではlib64

auth_param digest program /usr/lib64/squid/digest_pw_auth /etc/squid/digpass

#暗号化のレベル?
auth_param digest children 5

#ダイアログに表示される文字列(realm)
auth_param digest realm Proxy-caching web server! Only authenticated user can use.

#以下よくわからないがデフォルトの設定を流用
auth_param digest nonce_garbage_interval 5 minutes
auth_param digest nonce_max_duration 30 minutes
auth_param digest nonce_max_count 50

#ACL(Access Control List)の設定,デフォルト
acl all src 0.0.0.0/0.0.0.0
acl manager proto cache_object
acl localhost src 127.0.0.1/255.255.255.255 #追加
acl localnet src 192.168.0.0/255.255.255.0
acl password proxy_auth REQUIRED #認証用,これがないと認証が行われない
acl to_localhost dst 127.0.0.0/8
acl SSL_ports port 443
acl Safe_ports port 80 # http
acl Safe_ports port 21 # ftp
acl Safe_ports port 443 # https
acl Safe_ports port 70 # gopher
acl Safe_ports port 210 # wais
acl Safe_ports port 1025-65535 # unregistered ports
acl Safe_ports port 280 # http-mgmt
acl Safe_ports port 488 # gss-http
acl Safe_ports port 591 # filemaker
acl Safe_ports port 777 # multiling http
acl CONNECT method CONNECT

#http_accessについて
http_access allow localhost
http_access allow localnet #追加,LANからのアクセスは認証無し
http_access allow password #追加,認証用
http_access deny all

他はデフォルトです。

digpassについて
digpassというファイルにユーザ名とパスワードを平文で記述します。
user1:password1
user2:password2
...

ブラウザ側で暗号化されたものを、digpassに記述してあるユーザ,パスワードの計算結果と比較するのかな?
最新(Version 3?)のsquidはdigpasshtdigestで暗号化しておけるようです。


とりあえずsquidを起動
/etc/init.d/squid start


ブラウザのプロキシの設定をしてアクセス
アドレス マシンのIPアドレス
ポート 3128(http_portで指定したもの)

そうすると…

図2. ブラウザの認証画面

図3. 認証を拒否した場合


すごいな。
これでプラグイン等を組み込むとコンテンツフィルタにもなるらしいです。素敵。
他にもいろいろな機能があってキャッシングやリバースプロキシなんかもできます。

Googleでの記事検索