架設(shè)一臺(tái)代理,提供對(duì)外網(wǎng)用戶(hù)的代理請(qǐng)求,端口仍然為3128,加入Squid認(rèn)證功能。這樣可以保證只提供給某些你信任的用戶(hù)該服務(wù)。架設(shè)過(guò)程和架設(shè)對(duì)內(nèi)網(wǎng)用戶(hù)提供服務(wù)的過(guò)程基本相同,只是在編譯安裝squid時(shí)和squid的配置文件squid.conf有些不同。這次架設(shè)的服務(wù)器將保留對(duì)內(nèi)網(wǎng)用戶(hù)提供squid服務(wù)(內(nèi)網(wǎng)用戶(hù)不增加認(rèn)證功能限制)的同時(shí)再增加對(duì)外網(wǎng)用戶(hù)提供squid+認(rèn)證功能。版本為FreeBSD6.2-RELEASE+Squid2.6-STABLE12。
服務(wù)器及網(wǎng)絡(luò)信息:
外網(wǎng)網(wǎng)卡:em0;外網(wǎng)ip:221.6.117.50/255.255.255.240
內(nèi)網(wǎng)網(wǎng)卡:em1;內(nèi)網(wǎng)ip:128.0.0.4/255.255.252.0
架設(shè)過(guò)程:
一、FreeBSD的安裝
1、最小化安裝FreeBSD6.2RELEASE
2、配置內(nèi)核:
jiulongproxynew# cd /usr/src/sys/i386/conf
jiulongproxynew# cp GENERIC funpower
jiulongproxynew# ee funpower
修改內(nèi)核配置文件,將不需要的選項(xiàng)(如網(wǎng)卡)之類(lèi)的前面打#,然后按esc并按a保存退出,再執(zhí)行:
jiulongproxynew# /usr/sbin/config funpower
jiulongproxynew# cd ../compile/funpower
jiulongproxynew# make cleandepend
jiulongproxynew#make depend
jiulongproxynew# make
jiulongproxynew# make install
3、配置/etc/rc.conf:
hostname="jiulongproxynew.jscpu.com"
defaultrouter="221.6.117.97"
ifconfig_em0="inet 221.6.117.50 netmask 255.255.255.240"
ifconfig_em1="inet 128.0.0.4 netmask 255.255.252.0"
sendmail_enable="NONE"
inetd_enable="YES"
linux_enable="YES"
sshd_enable="YES"
usbd_enable="YES"
4、配置resolv.conf:
jiulongproxynew# cd /etc
jiulongproxynew# ee resolv.conf
添加如下兩行:
nameserver 221.6.96.177
nameserver 221.6.96.178
5、重啟服務(wù)器
二、squid的安裝
1、安裝perl以支持squid
jiulongproxynew# cd /usr/ports/lang/perl5
jiulongproxynew# make install
2、安裝Apache,squid認(rèn)證用戶(hù)設(shè)置密碼時(shí)使用apache的密碼管理程序htpasswd
jiulongproxynew# cd /usr/ports/www/apache13
jiulongproxynew# make install
3、下載并安裝squid
從http://www.squid-cache.org/Versions/v2/2.6/下載squid-2.6.STABLE16.tar.gz并通過(guò)FTP放置服務(wù)器目錄中/home/funpower,然后開(kāi)始解壓安裝:
jiulongproxynew# cd /home/funpower
jiulongproxynew# tar zxvf squid-2.6.STABLE16.tar.gz
jiulongproxynew# cd squid-2.6.STABLE16
jiulongproxynew# ./configure –prefix=/usr/local/squid –enable-auth=”basic” –enable-basic-auth-helpers=”NCSA”
jiulongproxynew# make
jiulongproxynew#make install
3、配置squid和創(chuàng)建認(rèn)證用戶(hù)及密碼
將ncsa_auth拷貝至可執(zhí)行目錄/usr/sbin
jiulongproxynew# cd /home/funpower/squid-2.6.STABLE16
jiulongproxynew# cd helpers/basic_auth/NCSA/
jiulongproxynew# cp ncsa_auth /usr/sbin
創(chuàng)建squid認(rèn)證用戶(hù)www
jiulongproxynew# /usr/local/bin/htpasswd -c /usr/local/squid/etc/password www
New password:
Re-type new password:
Adding password for user www
輸入www兩遍密碼后出現(xiàn)上面的信息就說(shuō)明用戶(hù)創(chuàng)建成功。
4、配置squid.conf
jiulongproxynew# cd /usr/local/squid/etc
jiulongproxynew# ee squid.conf
內(nèi)容如下:
auth_param basic program /usr/sbin/ncsa_auth /usr/local/squid/etc/password
auth_param basic children 5
auth_param basic realm Please enter the user name and password
auth_param basic credentialsttl 2 hours
acl web src 128.0.0.0/22 //內(nèi)網(wǎng)ip段定義
acl all src 0.0.0.0/0.0.0.0 //外網(wǎng)ip段定義
acl all1 proxy_auth REQUIRED //定義all1字段為需要認(rèn)證
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
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
#deny bbs
acl bbs url_regex -i bbs
http_access deny bbs
#deny baidu post
acl baidupost dstdom_regex post.baidu.com
acl baidupost2 dstdomain post.baidu.com
http_access deny baidupost
http_access deny baidupost2
http_access allow manager localhost
http_access deny manager
http_access deny !Safe_ports
http_access deny CONNECT !SSL_ports
http_access allow web //定義內(nèi)網(wǎng)ip段為允許通過(guò)
http_access allow all all1 //定義外網(wǎng)ip段為允許通過(guò),但需要認(rèn)證,因?yàn)榧恿薬ll1字段
icp_access allow all
http_port 3128
http_port 221.6.117.x:3128 //增加一個(gè)對(duì)本機(jī)外網(wǎng)地址的3128端口
hierarchy_stoplist cgi-bin ?
acl QUERY urlpath_regex cgi-bin \?
cache deny QUERY
cache_mem 64 MB
cache_dir ufs /usr/local/squid/cache 7000 16 256
access_log /dev/null
cache_log /dev/null
cache_store_log none
refresh_pattern ^ftp: 1440 20% 10080
refresh_pattern ^gopher: 1440 0% 1440
refresh_pattern . 0 20% 4320
acl apache rep_header Server ^Apache
broken_vary_encoding allow apache
cache_mgr webmaster@jscpu.com
cache_effective_user squid
cache_effective_group squid
visible_hostname jiulongproxynew.jscpu.com
4、創(chuàng)建用戶(hù)及緩存等:
jiulongproxynew# pw groupadd squid
jiulongproxynew# pw adduser squid -g squid -s /nonexistent
jiulongproxynew# mkdir /usr/local/squid/cache
jiulongproxynew# chown -R squid /usr/local/squid/cache
jiulongproxynew# chgrp -R squid /usr/local/squid/cache
jiulongproxynew# chown -R squid /usr/local/squid/var/logs
jiulongproxynew# chgrp -R squid /usr/local/squid/var/logs
jiulongproxynew# /usr/local/squid/sbin/squid -z
jiulongproxynew# cd /usr/local/squid/sbin
jiulongproxynew# ./squid
jiulongproxynew# ee /etc/rc.local
加入如下一行:
/usr/local/squid/sbin/squid
保存退出。
5、重啟服務(wù)器
三、客戶(hù)端的設(shè)置及上網(wǎng)演示
1、內(nèi)網(wǎng)用戶(hù)
內(nèi)網(wǎng)用戶(hù)因?yàn)闆](méi)有增加squid代理的認(rèn)證功能,所以上網(wǎng)設(shè)置不變,只需在IE瀏覽器中設(shè)置服務(wù)器內(nèi)網(wǎng)網(wǎng)卡地址128.0.0.4及3128端口即可。如下圖:

2、外網(wǎng)(家庭)用戶(hù)
外網(wǎng)用戶(hù),一般是家中,在使用該代理,需將IE上的代理服務(wù)器地址設(shè)置為該服務(wù)器的外網(wǎng)網(wǎng)卡地址221.6.117.50,端口仍為3128。如下圖:

設(shè)置完后,在IE上打開(kāi)任一網(wǎng)址,即會(huì)跳出一認(rèn)證對(duì)話框,如下圖,輸入剛才創(chuàng)建的www用戶(hù)及密碼,若能訪問(wèn)該網(wǎng)站,及該服務(wù)器架設(shè)正確。