FreeBSD/squid

squid【スクイッド】

dokuwiki.fl8.jp掲載済

スクイッドと読むらしいですね。日本語訳するとヤリイカの事だそうです。
squidでプロキシキャッシュサーバを作成してみたいと思います。

環境

FreeBSD 6.0
squid 2.5

インストール

# cd /usr/ports/www/squid
# make install clean ;rehash


/usr/local/etc/squid/squid.confを設定

ログディレクトリとキャッシュディレクトリを変更しました。

no_cache deny QUERY
cache_dir ufs /work/squid 100 16 256
↑cacheフォルダの場所指定/キャッシュ容量/サブフォルダ数/更にサブフォルダ数
cache_log /var/squid/cache.log
cache_store_log /var/squid/store.log
pid_filename /var/run/squid/squid.pid
auth_param basic children 5
auth_param basic realm Squid proxy-caching web server
auth_param basic credentialsttl 2 hours
auth_param basic casesensitive off
refresh_pattern ^ftp:           1440    20%     10080
refresh_pattern ^gopher:        1440    0%      1440
refresh_pattern .               0       20%     4320
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 to_localhost dst 127.0.0.0/8
acl SSL_ports port 443 563
acl Safe_ports port 80          # http
acl Safe_ports port 21          # ftp
acl Safe_ports port 443 563     # https, snews
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
acl private src 192.168.1.0/255.255.255.0
http_access allow manager localhost
http_access allow private
http_access deny manager
http_access deny !Safe_ports
http_access deny CONNECT !SSL_ports
http_access deny all
http_reply_access allow all
icp_access allow all
header_access Cache-Control deny all
header_access Via deny all
header_access X-Forwarded-For deny all
header_access Server deny all
header_access User-Agent deny all
header_access Accept allow all
header_replace User-Agent Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)
coredump_dir /var/log/squid

runディレクトリとlogディレクトリ作成

# mkdir /var/run/squid
# chmod squid:wheel /var/run/squid
# mkdir /var/log/squid
# chmod squid:wheel /var/log/squid

起動

■squid.conf修正後、下記のコマンドでキャッシュディレクトリを作成する。

# squid -z

■起動シェルにて起動。

# /usr/local/etc/rc.d/squid start

確認

後はブラウザにProxy設定をして確認します。⇒Windows/Proxy
これ⇒診断君でチェックしてみました。

キャッシュクリア

■下記の手順でキャッシュクリアできます。起動シェルなどに組み込んだ方がいいかもしれません。

# /usr/local/etc/rc.d/squid stop
# rm -rf /usr/local/squid/cache/*
# squid -z
# /usr/local/etc/rc.d/squid start

ログローテート

■squidのログローテートは下記のコマンドで行います。

# /usr/local/sbin/squid -k rotate

■cronに設定しておく(月に一回ローテートする設定例)

0 0 1 * * /usr/local/bin/sudo /usr/local/sbin/squid -k rotate

キャッシュさせたくない場合

■/usr/local/etc/squid/squid.confでno_cashで指定する。

# vi /usr/local/etc/squid/squid.conf
------------------例---------------------
acl QUERY1 urlpath_regex cgi-bin \?
no_cache deny QUERY1
↑cgi-bin ?を含むURLをキャッシュしない
acl SERVER1 dstdomain www.flateight.com
no_cache deny SERVER1
↑www.flateight.comのドメインをキャッシュしない
no_cac
acl QUERY2 url_regex yahoo\.co\.jp
no_cache deny QUERY2
↑yahoo.co.jpを含むURLをキャッシュしない
-------------------例--------------------

設定後は一回サービスをリスタートします。

参考サイト

http://www.ryuon.org/FreeBSD/install_manual/15.squid.txt

Basic認証の設定

パスワードの設定

Apacheのhtpasswdを使用します。プログラムのディレクトリと、パスワードファイルの保存先は適宜

# htpasswd -c /usr/local/squid/passwd username

squid.confの編集

下記を設定します。auth_paramのディレクトリは適宜。http_accessのallow設定では、ネットワークのallow設定(例:http_access allow mylocal)はコメントアウトしておく。

#  TAG: auth_param
auth_param basic program /usr/local/libexec/squid/ncsa_auth /usr/local/etc/squid/passwd

#  TAG: acl
acl password proxy_auth REQUIRED

#  TAG: http_access
http_access allow password