2011年4月2日

Proxy 伺服器認證 (squid + ncsa )

proxy 伺服器 ( squid ) 除了用 IP 當連線範圍之外,
如果在範圍 IP 之外,
仍想要用該 proxy 的話,
可以加掛認證模組進來,
只要輸入正確的 帳號/密碼 ,
就算在範圍IP之外,
依然可以通過 proxy 。

我的工作環境:CentOS Server 3.9、squid-2.5.STABLE3-9.3E。

squid 認證方式採用 ncsa_auth 。

 

1.首先進行允許任何地方連線,
修改 squid.conf ,
將以下 code 放在 http_access deny all 上面。

http_access allow all

2.確認系統中有安裝 httpd (apache) 伺服器,因為以下的指令是來自 httpd 。
用 htpasswd 建立一位可以使用 proxy 的帳號及密碼:

# htpasswd -c proxy_passwd_file user001

完畢之後會在目前目錄產生一個 proxy_passwd_file 的密碼檔,
建議將這個檔案放到 squid 的目錄去,
以方便管理。

# mv proxy_passwd_file /etc/squid/

3.修改 /etc/squid/squid.con 檔,
在認證段落加上以下兩行:

auth_param basic realm Please enter your name and password.
auth_param basic program /usr/lib/squid/ncsa_auth /etc/squid/proxy_passwd_file

4.並把 acl password proxy_auth REQUIRED 取消註解。

5.在原本限制 IP 段落之後、http_access allow all 之前,加入

http_access allow password

6.把這一行註解掉

#http_reply_access allow all

7.到這邊應該就設定完畢了,重新啟動 squid 吧!

# /etc/init.d/squid restart