squid的代理功能配置
調整Cache的選項
l request_header_max_size 數字(KB)
最大http請求頭
l request_body_max_size 數字(KB)
最大http請求數據內容
l reply_body_max_size 數字(KB)
最大返回數據,可限制用戶下載的數據大小
l reference_age 數字
LRU算法中指定LRU時間
l quick_abort_min 數字(KB)
斷點續傳最小值
l quick_abort_max 數字(KB)
斷點續傳最大值
l quick_abort_pct 數字(percent)
超過值認爲續傳成功
l negative_ttl 數字 minutes/hours/seconds
否定回答TTL
l positive_dns_ttl 數字 minutes/hours/seconds
DNS肯定回答TTL
l range_offset_limit 數字 KB/MB/Bytes
請求SQUID預取數據的大小
(3) 定義超時的選項
l connect_timeout:SQUID等待客戶請求的服務器迴應的時間長度
l peer_connect_timeout:一個對等的緩存服務器的TCP連接超時時間
l client_lifetime:客戶端同代理服務器TCP連接的最大時間長度
l read_timeout:讀入數據超時
l request_timeout:客戶端請求最大時間
l shutdown_lifetime:關閉squid緩存時間
(4) 定義訪問控制的選項
l acl:定義一個訪問列表
格式:acl aclname acltype string
類型:(acltype)
• src:源地址
• dst:目標地址
• srcdomain:原(客戶)名稱
• dstdomain:目標名稱
• time:時間(M星期一、T星期二、W星期三、H星期四、F星期五、A星期六、S星期天)
• url_regex [-i]:URL中的正則表達式匹配
• urlpath_regex[-i]:略去協議和主機名的正則表達式
• proxy_auth:通過外部程序進行用戶驗證
• maxconn:單IP最大連接數
• port:端口
• myip:本地IP
• srcdom_regex [-i]:匹配客戶名
• dstdom_regex [-i]:匹配目標名
• myport:我的端口
• proto:協議,http,ftp..
• method:方法, GET POST
• browser:匹配User-Agent header
• arp:匹配指定的MAC地址
• proxy_auth username:指定合法用戶,用REQUIRED表示所有合法用戶
l http_access:代理訪問控制
格式:http_access allow|deny [!] acl_name
l icp_access:icp訪問控制
格式:icp_access allow|deny [!]acl_name
l cache_peer_access:其它緩存服務器訪問控制
格式:cache_peer_access cache_host allow|deny [!]acl_name
(5) 管理員參數選項
l cache_mgr mail地址:管理員電子郵件
l cache_effective_user 用戶名:運行身份
l cache_effective_group 組名:運行組身份
(6) CACHE註冊服務選項
l announce_period 數字:發佈緩存通告頻率
l announce_host 主機名:通告的主機
l announce_file 文件名:通告的信息
l announce_port 端口號:通告的對方端口
(7) HTTPD加速選項
l httpd_accel_host 主機名/vitual:加速某服務器訪問
l httpd_accel_port 端口號:加速服務器的對方端口
l httpd_accel_single_host on/off:多臺服務器時設置off
l httpd_accel_with_proxy on/off:即作爲加速器,又作爲WEB緩存服務器,設置爲on
l httpd_accel_uses_host_header on/off:爲on,能支持不同的http協議
(8) 雜項
l logfile_rotate 0-9:日誌輪換版本數
l append_domain 域名:默認域名
l tcp_recv_bufsize 數字(KB):TCP緩存區大小
l err_html_text 字符串:包含在錯誤消息中的文本
l deny_info:禁用時顯示消息
格式:deny_info err_page_name acl
l visible_hostname 主機名
錯誤消息中顯示的服務器名稱
l error_directory 路徑:指定錯誤消息文件目錄
2. 啓動squid服務
#service squid start
二. 配置案例
案例一: 普通的代理服務器
利用squid架設一臺普通的代理服務器,代理LAN(192.168.7.0/24)接入internet,並對客戶進行身份驗證
1. 安裝squid
#rpm -ivh squid-2.5.STABLE1-2.i386.rpm
2. 配置squid.conf文件
#vi /etc/squid/squid.conf
http_port 8000
cache_mem 128 MB
cache_dir ufs /var/spool/squid 4096 16 256
cache_effective_user squid
cache_effective_group squid
dns_nameservers 202.102.192.68
cache_access_log /var/log/squid/cache.log
cache_store_log /var/log/squid/store.log
visible_hostname ww.abc.com
cache_mgr [email protected]
auth_param basic program /usr/lib/squid/ncsa_auth /etc/squid/passwd
auth_param basic children 5
auth_param basic credentialsttl 2 hours
auth_param basic realm linux.com’squid
acl lan src 192168.7.0/255.255.255.0
acl users proxy_auth REQUIRED
http_access allow lan users
3. 建立squid用戶
#htpasswd –c /etc/squid/passwd px1
4. 啓動服務
#service squid start
案例二:透明代理服務器
利用Squid架設透明代理服務器.使LAN(192.168.7.0)可以接入internet
1. 安裝squid
#rpm -ivh squid-2.5.STABLE1-2.i386.rpm
2. 配置squid.conf文件
#vi /etc/squid/squid.conf
http_port 8000
cache_mem 128 MB
cache_dir ufs /var/spool/squid 4096 16 256
cache_effective_user squid
cache_effective_group squid
dns_nameservers 202.102.192.68
cache_access_log /var/log/squid/cache.log
cache_store_log /var/log/squid/store.log
visible_hostname ww.abc.com
cache_mgr [email protected]
httpd_accel_host virtual
httpd_accel_port 80
httpd_accel_with_proxy on
httpd_accel_uses_host_header on
acl lan src 192168.7.0/255.255.255.0
http_access allow lan
3. 啓動服務
#service squid start
案例三:反向代理服務器
1. 安裝squid
#rpm -ivh squid-2.5.STABLE1-2.i386.rpm
2. 配置squid.conf文件
#vi /etc/squid/squid.conf
http_port 8000
cache_mem 128 MB
cache_dir ufs /var/spool/squid 4096 16 256
cache_effective_user squid
cache_effective_group squid
dns_nameservers 202.102.192.68
cache_access_log /var/log/squid/cache.log
cache_store_log /var/log/squid/store.log
visible_hostname ww.abc.com
cache_mgr [email protected]
http_port 80 # squid監聽的端口
httpd_accel_host 172.16.250.250 # 內部WEB服務器的IP地址
httpd_accel_port 80 # WEB服務器的IP地址
httpd_accel_single_host on # 轉發爲緩衝的請求到一臺單獨的機器
httpd_accel_with_proxy on #
httpd_accel_uses_host_header off
httpd_accel_host 172.16.250.250 # 內部WEB服務器的IP地址
httpd_accel_port 80 # WEB服務器的IP地址
httpd_accel_single_host on # 轉發爲緩衝的請求到一臺單獨的機器
httpd_accel_with_proxy on #
httpd_accel_uses_host_header off
acl lan src 192168.7.0/255.255.255.0
http_access allow lan
3. 啓動服務
#service squid start