小Q:我认识的最成功的首席执行官刚开始都不只是为了钱--他们都梦想用自己的产品或

      服务改变世界,钱会随之而来的。---奥巴马在佐治亚州莫尔豪斯学院毕业典礼上说



----------------squid日志不记录指定类型文件----------------------

在squid.conf中加入:

acl nolog urlpath_regex -i \.css \.js \.swf \.jpg \.gif \.png \.jpeg

access_log /var/log/squid/access.log common !nolog

#其中common 为日志格式


----------------------squid代理用户认证------------------------- 

用authentication helpers添加身份验证

有如下几种认证方式 :

=> NCSA: Uses an NCSA-style username and password file.

=> LDAP: Uses the Lightweight Directory Access Protocol

=> MSNT: Uses a Windows NT authentication domain.

=> PAM: Uses the Linux Pluggable Authentication Modules scheme.

=> SMB: Uses a SMB server like Windows NT or Samba.

=> getpwam: Uses the old-fashioned Unix password file.

=> SASL: Uses SALS libraries.

=> NTLM, Negotiate and Digest authentication

配置NCSA 认证

创建认证用户名/密码,用htpasswd,需要apache:

#htpasswd  /etc/squid/passwd user1

输入密码

确定squid是否支持authentication helper

yum 安装的

#rpm -ql squid | grep ncsa_auth

输出:

/usr/lib64/squid/ncsa_auth

配置SQUID认证

vi /etc/squid/squid.conf

加入验证部分内容:

auth_param basic program /usr/lib64/squid/ncsa_auth /etc/squid/passwd   

//定义squid密码文件与ncsa_auth文件位置

auth_param basic children 15                   //认证进程的数量

auth_param basic realm Squid proxy-caching web server

auth_param basic credentialsttl 2 hours        //认证有效期

auth_param basic casesensitive off             //用户名不区分大小写,可


改为ON区分大小写

添加 acl 验证用户:

acl ncsa_users proxy_auth REQUIRED

http_access allow ncsa_users


重启: /etc/init.d/squid restart


----------------------配置防盗链-----------------------

在squid.conf中的acl段添加如下配置:

acl has_referer referer_regex 

acl allow_referer referer_regex -i baidu\.com

acl allow_referer referer_regex -i google\.com

acl allow_referer referer_regex -i yahoo\.cn


http_access allow !has_referer

http_access deny !allow_referer

deny_info http://img1.test.com/p_w_picpaths/noposter.jpg allow_referer


has_referer匹配Referer存在,然后利用!has_referer来匹配没有Referer即直接访问的请求,这部分请求不予做防盗链处理,allow。

allow_referer即允许使用源站资源的网站,然后利用!allow_referer来匹配不在允许列表的网站,这些不允许的Referer过来的请求就返回deny_info的内容


---------------------查看squid缓存-------------------

命令:  squidclient -h host -p port mgr:info

比如:  /usr/local/squid/bin/squidclient -h 127.0.0.1 -p 8080 mgr:info


使用这个命令的前提是,你在你的squid.conf 中配置了相关的选项

acl manager proto cache_object

http_access allow manager


---------------------删除squid缓存---------------------

首先在squid 的主配置文件中添加acl 列表,并允许受信任的主机有权限清除缓存   

  acl  managercache   src 192.168.1.145 127.0.0.1

  acl   Purge  method PURGE

  http_access allow  managercache Purge

  http_access  deny Purge

清除squid 中一条缓存

  /usr/local/squid/bi/squidclient -h  192.168.1.145 -p80 -m PURGE  

  http://www.linuxidc.com/404.html

批量清除squid 缓存中的文件

 

 #脚本 如下
    #!/bin/sh
   squidcache_path="/usr/local/squid/var/cache/"
   squidclient_path="/usr/local/squid/bin/squidclient"
   grep -a -r $1 $squidcache_path/* | strings | grep "http:" | awk -
F'http:' '{print "http:"$2;}' > cache_list.txt
   for url in `cat cache_list.txt`; do
   $squidclient_path -m PURGE -p80 $url
   done

  注:squidcache_path 是squid 缓存路径  squidclient_path 是squidclient命令的路径

      -p  是指定squid 监听的端口        并给clearcache.sh    执行权限     

  chmod +x  clearcache.sh

使用方法

    1、清除所有Flash缓存(扩展名.swf):

      ./clear_squid_cache.sh swf

  2、清除URL中包含sina.com.cn的所有缓存:

    ./clear_squid_cache.sh sina.com.cn

  3、清除文件名为zhangyan.jpg的所有缓存:

     ./clear_squid_cache.sh zhangyan.jpg



衔接地址:http://beibing.blog.51cto.com/10693373/1700901