squidclient服务端Squid的配置

简介:

一)在/usr/local/squid/etc/squid.conf(具体位置要看编译时的prefix参数),注意和cache manager相关的行:

 

 
  1. #Recommended minimum configuration: 
  2. acl all src 0.0.0.0/0.0.0.0 
  3. acl manager proto cache_object 
  4. acl localhost src 127.0.0.1/255.255.255.255 
  5. acl to_localhost dst 127.0.0.0/8 
  6. acl SSL_ports port 443 
  7. acl Safe_ports port 80 # http 
  8. acl Safe_ports port 21 # ftp 
  9. acl Safe_ports port 443 # https 
  10. acl Safe_ports port 70 # gopher 
  11. acl Safe_ports port 210 # wais 
  12. acl Safe_ports port 1025-65535 # unregistered ports 
  13. acl Safe_ports port 280 # http-mgmt 
  14. acl Safe_ports port 488 # gss-http 
  15. acl Safe_ports port 591 # filemaker 
  16. acl Safe_ports port 777 # multiling http 
  17. acl CONNECT method CONNECT 
  18.  
  19. # 
  20. # Only allow cachemgr access from localhost 
  21. http_access allow manager localhost 
  22. http_access deny manager 
  23. # Deny requests to unknown ports 
  24. http_access deny !Safe_ports 
  25. # Deny CONNECT to other than SSL ports 
  26. http_access deny CONNECT !SSL_ports 
  27.  
  28. # And finally deny all other access to this proxy 
  29. http_access deny all 
  30.  
  31.  
  32. # TAG: cachemgr_passwd 
  33. # Specify passwords for cachemgr operations. 
  34. # 
  35. # Usage: cachemgr_passwd password action action ... 
  36. # 
  37. # Some valid actions are (see cache manager menu for a full list): 
  38. # 5min 
  39. # 60min 
  40. # asndb 
  41. # authenticator 
  42. # cbdata 
  43. # client_list 
  44. # comm_incoming 
  45. # config * 
  46. # counters 
  47. # delay 
  48. # digest_stats 
  49. # dns 
  50. # events 
  51. # filedescriptors 
  52. # fqdncache 
  53. # histograms 
  54. # http_headers 
  55. # info 
  56. # io 
  57. # ipcache 
  58. # mem 
  59. # menu 
  60. # netdb 
  61. # non_peers 
  62. # objects 
  63. # offline_toggle * 
  64. # pconn 
  65. # peer_select 
  66. # redirector 
  67. # refresh 
  68. # server_list 
  69. # shutdown * 
  70. # store_digest 
  71. # storedir 
  72. # utilization 
  73. # via_headers 
  74. # vm_objects 
  75. # 
  76. # * Indicates actions which will not be performed without a 
  77. # valid password, others can be performed if not listed here. 
  78. # 
  79. # To disable an action, set the password to "disable". 
  80. # To allow performing an action without a password, set the 
  81. # password to "none". 
  82. # 
  83. # Use the keyword "all" to set the same password for all actions. 
  84. # 
  85. #Example: 
  86. # cachemgr_passwd secret shutdown 
  87. # cachemgr_passwd lesssssssecret info stats/objects 
  88. # cachemgr_passwd disable all 
  89. # 
  90. #Default: 
  91. # none 

我们需要在acl指令、http_access指令和cachemgr_passwd指令都添加相关的参数。

起作用的是以下的指令:

 

 
  1. acl localhost src 127.0.0.1/255.255.255.255 
  2. acl manager proto cache_object 
  3. # 允许本地用户清除缓存 
  4. acl Purge method PURGE 
  5. http_access allow Purge localhost 
  6. http_access deny Purge 
  7. # Only allow cachemgr access from localhost 
  8. http_access allow manager localhost 
  9. http_access deny manager 
  10. # 对于查看配置,关闭Squid等这类重要操作禁用掉 
  11. cachemgr_passwd disable config shutdown authenticator offline_toggle 
  12. # 对于不大查询的操作使用不使用密码 
  13. cachemgr_passwd none info stats/objects 
  14. # 对于其它操作密码保护 
  15. # cachemgr_passwd secretP all 

二)检验我们的配置

访问不需要密码的项:


 
  1. squidclient -p80 cache_object://localhost/info 

或者


 
  1. squidclient -p80 -h localhost mgr:info 

访问需要密码的项:

 
  1. squidclient -p80 cache_object://localhost/menu@secretP 

注:该命令常用来有权限访问的项

或者


 
  1. squidclient -p80 -h localhost mgr:menu@secretP 

删除缓存:


 
  1. squidclient -m PURGE http://url 

 

下面是默认的权限(未做配置):

 
  1. # squidclient -p80 -h www.xxx.xxx mgr: 
  2. HTTP/1.0 200 OK 
  3. Server: squid/2.6.STABLE10 
  4. Date: Sat, 26 Mar 2011 14:41:47 GMT 
  5. Content-Type: text/plain 
  6. Expires: Sat, 26 Mar 2011 14:41:47 GMT 
  7. Last-Modified: Sat, 26 Mar 2011 14:41:47 GMT 
  8. X-Cache: MISS from webcache 
  9. X-Cache-Lookup: MISS from webcache:80 
  10. Via: 1.0 webcache:80 (squid/2.6.STABLE10) 
  11. Proxy-Connectionclose 
  12.  
  13.  mem                    Memory Utilization      public 
  14.  cbdata                 Callback Data Registry Contents public 
  15.  events                 Event Queue     public 
  16.  squidaio_counts        Async IO Function Counters      public 
  17.  config                 Current Squid Configuration     hidden 
  18.  ipcache                IP Cache Stats and Contents     public 
  19.  fqdncache              FQDN Cache Stats and Contents   public 
  20.  idns                   Internal DNS Statistics public 
  21.  external_acl           External ACL stats      public 
  22.  http_headers           HTTP Header Statistics  public 
  23.  menu                   This Cachemanager Menu  public 
  24.  shutdown               Shut Down the Squid Process     hidden 
  25.  offline_toggle         Toggle offline_mode setting     hidden 
  26.  info                   General Runtime Information     public 
  27.  filedescriptors        Process Filedescriptor Allocation       public 
  28.  objects                All Cache Objects       public 
  29.  vm_objects             In-Memory and In-Transit Objects        public 
  30.  openfd_objects         Objects with Swapout files open public 
  31.  pending_objects        Objects being retreived from the network        public 
  32.  client_objects         Objects being sent to clients   public 
  33.  io                     Server-side network read() size histograms      public 
  34.  counters               Traffic and Resource Counters   public 
  35.  peer_select            Peer Selection Algorithms       public 
  36.  digest_stats           Cache Digest and ICP blob       public 
  37.  5min                   5 Minute Average of Counters    public 
  38.  60min                  60 Minute Average of Counters   public 
  39.  utilization            Cache Utilization       public 
  40.  histograms             Full Histogram Counts   public 
  41.  active_requests        Client-side Active Requests     public 
  42.  store_digest           Store Digest    public 
  43.  storedir               Store Directory Stats   public 
  44.  store_check_cachable_stats     storeCheckCachable() Stats      public 
  45.  store_io               Store IO Interface Stats        public 
  46.  pconn                  Persistent Connection Utilization Histograms    public 
  47.  refresh                Refresh Algorithm Statistics    public 
  48.  delay                  Delay Pool Levels       public 
  49.  forward                Request Forwarding Statistics   public 
  50.  client_list            Cache Client List       public 
  51.  asndb                  AS Number Database      public 
  52.  server_list            Peer Cache Statistics   public 

即:

默认设置hidden的项为:

 
  1. config shutdown offline_toggle 

它的含意是,如果服务端不配置密码,将不能被访问,默认是隐藏的。

这不同于配置为,这样不允许客户端访问这几个项,访问时状态为disable

 
  1. http_access disable config shutdown offline_toggle 

这也不同于被配置为hidden,这样也不允许客户端访问这几个项,不过访问时状态为protected

 
  1. http_access protected config shutdown offline_toggle 

三)配置允许以哪些域名和端口访问cache manager

修改/usr/local/squid/etc/squid/etc/cachemgr.conf(文件位置依赖于我们的编译选项)文件

,增加Host:Port的行。

例如我的配置:

# grep ^[^#] /etc/squid/etc/cachemgr.conf

 
  1. localhost:80 
  2. 192.168.88.51:80 
  3. squid01.wangxiaoyu.org:80 


本文转自xiaoyuwang 51CTO博客,原文链接:http://blog.51cto.com/wangxiaoyu/527268 ,如需转载请自行联系原作者





相关文章
|
5月前
|
Java 应用服务中间件 nginx
Nginx之服务端获取真实客户端IP
Nginx之服务端获取真实客户端IP
160 5
|
20天前
|
缓存 负载均衡 安全
Squid代理服务之反向代理模式
总之,Squid代理服务器在反向代理模式下扮演着一个中间层,它有助于提高性能、安全性和可用性,同时可以缓解后端服务器的负载。这使得它在许多不同的应用场景中都非常有用。
23 0
|
应用服务中间件 Apache Windows
nginx基于客户端访问IP重定向
最近换了一家公司,工作比较忙,因为工作环境的关系导致不能经常写博客了,暂时手里也就写了LDAP+Samba+Vsftp统一集中认证项目文档、weblogic集群部署安装文档,由于各种关系导致不能外发,哈哈!各位博友原谅!现在就写一篇关于nginx的重定向文档吧! 项目需求: 公司现在的网站架构是nginx+apache反向代理,现需要将客户端访问的某两个网段IP地址重定向到应用主页,其余的所有IP地址访问都重定向到维护页面。
1435 0
|
缓存 Linux 网络虚拟化
Squid缓存代理服务器
Squid缓存代理服务器
444 0
Squid缓存代理服务器
|
Web App开发 缓存 监控
|
Web App开发 缓存 监控
|
数据安全/隐私保护 缓存
|
Web App开发 测试技术 网络安全