相关命令,没有测试过
 
停止squid
  /usr/local/squid/sbin/squid -k shutdown
 
启用新配置

  /usr/local/squid/sbin/squid -k reconfig
 
通过crontab每小时截断/轮循日志
  59 * * * * /usr/local/squid/sbin/squid -k rotate
 
查看squid运行状况
  /usr/local/squid/bin/squidclient -p 80 mgr:info
  /usr/local/squid/bin/squidclient -p 80 mgr:5min
 
查看squid内存使用情况
  /usr/local/squid/bin/squidclient -p 80 mgr:mem
 
查看squid磁盘使用情况
  /usr/local/squid/bin/squidclient -p 80 mgr:diskd
 
查看squid已缓存列表(小心使用,可能会导致crash
  /usr/local/squid/bin/squidclient -p 80 mgrbjects
 
强制更新某个url
  /usr/local/squid/bin/squidclient -p 80 -m PURGE
http://img.test.com/h/a.jpg

 
查看squid缓存到内存cache中并返回给访问用户的项
  #cat /var/log/squid/access.log | grep TCP_MEM_HIT
 
查看squid缓存到磁盘cache中并返回给访问用户的项
  #cat /usr/local/squid/var/logs/access.log | grep TCP_HIT
 
查看没被squid缓存住,直接从原始服务器获取并返回给访问用户的项
  #cat /usr/local/squid/var/logs/access.log | grep TCP_MISS
 

 

控制 Squid 的访问
acl aclname <acltype> "file" | string ...
定义一个访问列表,能够定义的访问列表有以下类型 (常用的)
   acl aclname src      ip-address/netmask ...   (
客户端 IP 地址)
   acl aclname src      addr1-addr2/netmask ...  (
客户端 IP 地址范围)
   acl aclname dst      ip-address/netmask ...   (URL
主机对应的 IP 地址)
   acl aclname myip     ip-address/netmask ...   (
本地主机 IP 地址)

   acl aclname srcdomain   .foo.com ...    (客户端主机名,通过反向域名解析的客户端 IP 地址)
   acl aclname dstdomain   .foo.com ...    (URL
中的目标主机名)
   acl aclname srcdom_regex [-i] xxx ...   (
通过正则表达式匹配客户端主机名)
   acl aclname dstdom_regex [-i] xxx ...   (
通过正则表达式匹配 URL 中的目标主机名)

   acl aclname url_regex [-i] ^http:// ... (通过正则表达式匹配整个 URL)
   acl aclname urlpath_regex [-i] \.gif$ ... (
通过正则表达式匹配 URL 路径)

   acl aclname port     80 70 21 ...            (目的服务器的端口)
   acl aclname port     0-1024 ...         (
目的服务器的端口范围)
   acl aclname myport   3128 ...         (
本地主机的端口)
   acl aclname proto    HTTP FTP ...            (
使用的网络协议 Protocol)
   acl aclname method   GET POST ...            (HTTP
请求的类型)
   acl aclname browser  [-i] regexp ...         (
匹配 HTTP 请求中的 User-Agent 内容)
   acl aclname referer_regex  [-i] regexp ...   (
匹配 HTTP 请求中的 Referer 内容,注意大部分请求不包含 Referer 内容)

   acl aclname req_mime_type mime-type1 ...     (请求的内容类型 MIME,注意它不匹配返回文件的 MIME 类型)
   acl aclname rep_mime_type mime-type1 ...     (
返回的内容类型 MIME,注意不能在 http_access 中使用这类访问列表)

   acl aclname req_header header-name [-i] any\.regex\.here   (匹配 HTTP 请求的任意 Header 内容)

    通常访问列表中的正则表达式是大小写敏感的,如果需要大小写不敏感,请使用 -i 选项。常用的访问列表:
acl all src 0.0.0.0/0.0.0.0
 acl localhost src 127.0.0.1/255.255.255.255
acl manager proto cache_object

http_access allow|deny [!]aclname ...
使用指定的访问列表允许或禁止 HTTP 访问。
如果没有设置 http_access 规则,默认规则是拒绝访问。
如果请求没有 http_access 规则与之匹配,则默认规则与最后一条 http_access 规则的 allow/deny 设置相反。
因此,最后的规则常设置为 http_access allow all 或者 http_access deny all.
header_access header_name allow|deny [!]aclname ...
使用指定的访问列表检查 HTTP 请求的头,并且根据内容允许或禁止 HTTP 访问。cache_peer_domain cache-host [!]domain [domain ...]
  
限制被发送到指定的代理服务器的访问请求中包含的域名。
  
可以使用 cache_peer_domain 将针对不同域名的访问请求导向至各自的代理服务器或原始内容服务器。
  
例如: cache_peer_domain first_host   first.domain
          cache_peer_domain second_host  second.domain
cache_peer_access cache-host allow|deny [!]aclname ...
类似 cache_peer_domain,但是使用访问列表控制对代理服务器的访问。
语法与 http_access 和其他访问设置类似。
refresh_pattern [-i] regex min percent max [options]
定义指定内容对象的刷新规则。默认情况下,正则表达式是大小写敏感的,使用 -i 选项可以使其大小写不敏感。
min      
单位是分钟,未显式定义过期时间的内容对象使用 min 作为对象寿命的下限。percent   百分比,未显式定义过期时间的内容对象使用 Last-Modified 时间的百分比作为对象的寿命。
max      
单位是分钟,未显式定义过期时间的内容对象使用 min 作为对象寿命的上限。
  
推荐配置:
      refresh_pattern ^ftp:     1440      20%      10080
      refresh_pattern ^gopher:  1440       0%       1440
      refresh_pattern .         0         20%       4320
cache allow|deny [!]aclname ...
  
用于禁止特定的请求及响应不被 Squid 缓存,注意:用 cache 禁止缓存时,应该使用 deny.
  
默认的设置是 cache allow all. 推荐的设置如下:
   acl QUERY urlpath_regex cgi-bin \?
   cache deny QUERY
no_cache allow|deny [!]aclname ...
  
cache 设置相同。
hierarchy_stoplist (keywords)
  
指定一份 URL 关键字列表,使得包含这些关键字的请求直接被发送到原始服务器。
 
注意:never_direct 将覆盖这一设置。

 always_direct allow|deny [!]aclname ...
  
使用访问列表控制指定的请求被直接发送到原始服务器,而不经过任何其他代理服务器。
  
注意: 1) always_direct deny ... 不等于 never_direct allow ...
              2)
该设置与 Squid 如何缓存请求的对象无关。
never_direct
  
always_direct 相反,该设置使用访问列表使得指定的请求从不直接发送到原始服务器