Squidを見なおしてずっと活用しています。便利よね。一家に一台プロキシサーバー
Squidのメリット。
- 速い
- 簡単
- 分散
- 枯れてる
mod_proxy と比較した時、squid の方がApacheと切り離して管理できるので、放置する文意はまぁ楽かもしれません。
Squidは分散キャッシュを使えるので複数台運用にはもってこいですね。あとリバースプロキシとしても大活躍中です。Windowsでキャッシュサーバーを構築するメリットはあまりないのですが。Windowsマシンをつけっ放して置いておくなら、電気代を有効活用するためにSquidサーバーとして使うことにしました。Cygwinでやっているのはもはや趣味のレベルですが。
また、LTEの7GB制限を回避するためにキャッシュと圧縮をやるのに役立ちそうです。
Opera Turboでもいいんだけどね
CygwinのデフォルトのSquid
インストール
apt-cyg install squid
/usr/sbin/squid #...無応答
動かない
SquidはCygwinに用意されていると、ググったら出てきたので、インストールしたら動かない。。。仕方ないのでコンパイルをしました。
Cygwin をSquidコンパイル
というプランです。結果から言うとSquid3系は簡単にコンパイルできるというわけでは無さそうでした。Squid2系は、TarBallをコンパイルしたら、直ぐに動きました。
コンパイル方法を参考に
コンパイル方法はSquidの公式Wikiに書いてあります
http://wiki.squid-cache.org/SquidFaq/CompilingSquidCygwin (Windows)
In order to compile Squid, you need to have Cygwin fully installed.
The usage of the Cygwin environment is very similar to other Unix/Linux environments, and -devel version of libraries must be installed.
WCCP is not available on Windows so the following configure options are needed to disable them:
--disable-wccp --disable-wccpv2
Squid will by default, install into /usr/local/squid. If you wish to install somewhere else, see the --prefix option for configure.
Now, add a new Cygwin user - see the Cygwin user guide - and map it to SYSTEM, or create a new NT user, and a matching Cygwin user and they become the squid runas users.
Read the squid FAQ on permissions if you are using CYGWIN=ntsec.
After run squid -z. If that succeeds, try squid -N -D -d1, squid should start. Check that there are no errors. If everything looks good, try browsing through squid.
Now, configure cygrunsrv to run Squid as a service as the chosen username. You may need to check permissions here.
--disable-internal-dns を付けてうまくいきました
./configure --disable-wccp --disable-wccpv2 --disable-internal-dns make make install
でうまくいきました。
make install 結果
/usr/local/squid にインストールされました
インストールされた結果は、こんな感じのディレクトリ構造になりました。
takuya@letsnote:~$ tree /usr/local/squid/ -L 2 /usr/local/squid/ ├── bin │ ├── cossdump.exe │ ├── RunCache │ └── squidclient.exe ├── etc │ ├── cachemgr.conf │ ├── mime.conf │ ├── mime.conf.default │ ├── squid.conf │ ├── squid.conf.default │ └── squid.htpasswd ├── libexec │ ├── cachemgr.exe │ ├── dnsserver.exe │ ├── ncsa_auth.exe │ └── unlinkd.exe ├── sbin │ └── squid.exe ├── share │ ├── errors │ ├── icons │ ├── man │ └── mib.txt └── var ├── cache └── logs
とりあえず プロキシとして動作させる。
設定をして、まずはフォワードプロキシとして動作確認
開始と停止を覚えてチェックする
init スクリプトによる自動起動が用意できないので手作業で起動です。
もし自動起動するなら、CygwinではサービスはCygserver経由ですしね。
起動
/usr/local/squid/sbin/squid
終了
/usr/local/squid/sbin/squid -k shutdown
ローカルホストからチェックする
早速チェックしましょう。今回は、グローバルIPにプロキシを置いたので確認君を遣いました。
ローカル環境なら、ローカル環境に phpinfo()のApacheサーバーにアクセスして、ホスト名が変わっているかProxy Via が付いたことを確認します。
確認くんでアクセス
アクセス制限を掛ける。
次に、アクセス制限を掛けます。このままでは、Squidはオープンプロキシなので各方面に面倒を掛ける転送屋さんになっています。悪用されて、謂れ無き非難を浴びるのは嫌なので、アクセス制限をかけましょう。
アクセス制限のモジュールをコンパイルします
アクセス制限設定
squid.confで次のように設定します。
#http_access allow all acl password proxy_auth REQUIRED http_access allow password auth_param basic program /usr/local/squid/libexec/ncsa_auth /usr/local/squid/etc/squid.htpasswd auth_param basic children 5 auth_param basic realm Squid proxy-caching web server #auth_param basic concurrency 0
パスワードファイルを作ります。
htpasswd -c /usr/local/squid/etc/squid.htpasswd takuya_1st
でパスワードファイルを作ります。
digest でもbasic でもいいのでとりあえずパスワードを掛けておけば安心ですね。
参考資料
http://notonly.blog36.fc2.com/blog-entry-1.html
http://serverfault.com/questions/176720/how-can-i-run-squid-in-cygwin
http://d.hatena.ne.jp/flying-foozy/20091210/1260445054
http://wiki.squid-cache.org/KnowledgeBase/Windows#Compiling_with_Cygwin
http://www.comfsm.fm/computing/squid/FAQ-11.html
http://www.mlexp.com/wiki/?squid%20%A5%E1%A5%E2#w0346b02
http://fedorasrv.com/squid.shtml