04.2.11

プロキシサーバーDeleGateの設定法


以下に、OS Xで多機能なプロキシサーバーDelegateを動作させる方法を
紹介します。


コンパイル

なるべく最新版のDelegateソースを取得する。ここではdelegate8.9.1を使用する。Delegate home

・コンパイルはmake一発。
・途中で訊かれるADMINにはroot@yourhostnameなどを答える。
・src/delegatedに出来た実行ファイルを/usr/local/binにコピーする。

パーミッションの訂正

以下の作業はすべてrootになって行う。

・まず一度起動してみる。
delegated -P8080 SERVER=http
・すると、/var/spool/delegate-nobody以下にいくつかのディレクトリが出来るので、 cacheディレクトリを追加した上で、これらのパーミッションを適正にする。
mkdir /var/spool/delegate-nobody/cache
chown nobody /var/spool/delegate-nobody
chown nobody /var/spool/delegate-nobody/*
chmod 755 /var/spool/delegate-nobody
chmod 755 /var/spool/delegate-nobody/*

設定ファイルを作成

delegateをプロクシとして適切に動作させるためのコンフィグファイルを /etc/proxy以下に3つ作成する。

/etc/proxy/parameters
--------------
-P8080
ADMIN=root@yourhostname
DGROOT=/var/spool/delegate-nobody
SERVER=http
RESOLV=dns,nis,file
RES_CONF=/etc/proxy/resolv.conf
PERMIT=http:*:localhost
CONNECT=cache,direct:*:*
EXPIRE=3d
CRON="0 2 * * * -expire 3d"
#HTTPCONF=kill-qhead:VIA
#HTTPCONF=add-qhead:REFERER:http://google.co.jp/
---------
/etc/proxy/proxy.pac (詳細)
---------
function FindProxyForURL(url, host)
{ 
	return "PROXY 127.0.0.1:8080";
}
----------
/etc/proxy/resolv.conf
----------
nameserver  IPアドレス
nameserver  IPアドレス
----------

自動起動させるための設定

OS Xを起動したときに、自動的にdelegateが立ち上がるように 設定する。

・/System/Library/StartupItems/DeleGateディレクトリを作成し、ここに 以下のふたつのファイルを置く。
/System/Library/StartupItems/DeleGate/DeleGate
-------
#!/bin/sh

. /etc/rc.common

##
# Start up DeleGate proxy server
##

if [ "${DELEGATED:=-NO-}" = "-YES-" ]; then

    ConsoleMessage "Starting DeleGate server"

    if [ -f /usr/local/bin/delegated ]; then
        limit stacksize 4096k
        /usr/local/bin/delegated +=/etc/proxy/parameters
    fi
fi
------
/System/Library/StartupItems/DeleGate/StartupParameters.plist
------
{
  Description     = "DeleGate proxy server";
  Provides        = ("DeleGate");
  Requires        = ("Resolver");
  OrderPreference = "None";
  Messages =
  {
    start = "Starting DeleGate proxy server";
    stop  = "Stopping DeleGate proxy server";
  };
}
-----
・そして、パーミッションを訂正。
chmod 755 /System/Library/StartupItems/DeleGate/DeleGate
chmod 655 /System/Library/StartupItems/DeleGate/StartupParameters.plist
・/etc/hostconfigに以下の1行を追加。
DELEGATED=-YES-

再起動

OS Xを再起動すれば、delegateが動作する。
各ブラウザのプロキシ設定で自動スクリプトに、"file://localhost/etc/proxy/proxy.pac" のような形で/etc/proxy/proxy.pacを指定する。

――終わり――