Chinaunix首页 | 论坛 | 博客
  • 博客访问: 5287209
  • 博文数量: 1144
  • 博客积分: 11974
  • 博客等级: 上将
  • 技术积分: 12312
  • 用 户 组: 普通用户
  • 注册时间: 2005-04-13 20:06
文章存档

2017年(2)

2016年(14)

2015年(10)

2014年(28)

2013年(23)

2012年(29)

2011年(53)

2010年(86)

2009年(83)

2008年(43)

2007年(153)

2006年(575)

2005年(45)

分类: LINUX

2006-05-09 09:18:26


--------------------------------------------------------------------------------
 
最近公司有人下载电影,严重影响上网速度,为杜绝此类情况再次发生,上面要求从技术手段上解决这个问题。
公司服务器用linux作为网关,通过squid+iptables透明代理上网,也有做QoS流量限制,但仍然有人在流量被限制的情况下开多线程下载电影,所以此次准备从squid代理入手,限制下载电影。

以下是squid.conf部分代码


CODE:[Copy to clipboard]#用户分类
acl advance arp 00:03:0d:32:39:92 00:05:5D:F6:B4:82
acl vipuser   arp 00:C0:9F:9B:20:53 00:00:E8:18:C1:64
acl LanUser src 192.168.1.3-192.168.1.24/32
acl localhost src 127.0.0.1/32
acl all src 0.0.0.0/0.0.0.0

#行为分类
acl Movies rep_mime_type video/mpeg
acl UPLIMIT req_header Content-Length [5-9][0-9]{5} [0-9]{7,}
acl download urlpath_regex -i \.mp3$ \.avi$ \.rmvb$ \.rm$ \.ra$ \.ram$ \.mpe$ \.smi$
acl denysite dstdomain .tencent.com
acl BadSites url_regex "/opt/squid/etc/badsites"
acl worktime time SMTWHFA 7:40-12:00 13:00-21:30


#具体规则
http_access allow advance
http_reply_access deny Movies worktime
http_access deny UPLIMIT
http_access deny download worktime
http_access allow vipuser
http_access deny badsites
http_access allow localhost
http_access deny denysite worktime
http_access allow LanUser
http_access deny all
其中


CODE:[Copy to clipboard]acl UPLIMIT req_header Content-Length [5-9][0-9]{5} [0-9]{7,}
是参考了

理想中,应该能实现限制超过10M大小的文件下载,并限制下载电影类文件。但是实际上并没有实现,电影照样能下载。
另外,通过


CODE:[Copy to clipboard]acl download urlpath_regex -i \.mp3$ \.avi$ \.rmvb$ \.rm$ \.ra$ \.ram$ \.mpe$ \.smi$
限制下载此类文件之后,可以限制,
但此类下载则无法限制。
这是为何?

请有经验的兄弟帮忙分析一下:)

 
另外,在squid的mime.conf里面,对于rmvb格式文件,应该如何写?


CODE:[Copy to clipboard]\.rmvb$         video/mpeg
还是


CODE:[Copy to clipboard]\.rmvb$         application/vnd.rn-realmedia

 

已经搞定了。
通过下载分析,发现下载rmvb格式时,http头返回的下载类型为application/vnd.rn-realmedia,故在mime.conf里面将rmvb格式类型对应为application/vnd.rn-realmedia,就可在squid.conf里面添加acl控制下载此类文件了。但关于下载文件大小限制,还存在问题,有兄弟实现了请告诉我一声:)

附flashget下载日志


CODE:[Copy to clipboard]Thu Apr 27 09:49:24 2006 已连接.
Thu Apr 27 09:49:24 2006 GET /down/movie/tv/gong/01.rmvb HTTP/1.1
Thu Apr 27 09:49:24 2006 Host: down3.tfol.com
Thu Apr 27 09:49:24 2006 Accept: */*
Thu Apr 27 09:49:24 2006 Referer:
Thu Apr 27 09:49:24 2006 User-Agent: Mozilla/4.0 (compatible; MSIE 5.00; Windows 98)
Thu Apr 27 09:49:24 2006 Range: bytes=334680-
Thu Apr 27 09:49:24 2006 Pragma: no-cache
Thu Apr 27 09:49:24 2006 Cache-Control: no-cache
Thu Apr 27 09:49:24 2006 Connection: close
Thu Apr 27 09:49:24 2006 HTTP/1.0 403 Forbidden
Thu Apr 27 09:49:24 2006 Server: squid/2.5.STABLE13
Thu Apr 27 09:49:24 2006 Mime-Version: 1.0
Thu Apr 27 09:49:24 2006 Date: Thu, 27 Apr 2006 01:50:05 GMT
Thu Apr 27 09:49:24 2006 Content-Type: text/html
Thu Apr 27 09:49:24 2006 Content-Length: 1121
Thu Apr 27 09:49:24 2006 Expires: Thu, 27 Apr 2006 01:50:05 GMT
Thu Apr 27 09:49:24 2006 X-Squid-Error: ERR_ACCESS_DENIED 0
Thu Apr 27 09:49:24 2006 X-Cache: MISS from HttpServer
Thu Apr 27 09:49:24 2006 Connection: close
Thu Apr 27 09:49:24 2006 有错误发生!
Thu Apr 27 09:49:24 2006 等待 5秒后重试

QUOTE:
原帖由 thatday 于 2006-4-27 09:55 发表
已经搞定了。
通过下载分析,发现下载rmvb格式时,http头返回的下载类型为application/vnd.rn-realmedia,故在mime.conf里面将rmvb格式类型对应为application/vnd.rn-realmedia,就可在squid.conf里面添加acl控制 ...
acl rmvb req_mime_type video/mpeg
reply_body_max_size 10240000 deny  rmvb

QUOTE:
原帖由 fangjy2008 于 2006-4-30 08:35 发表

acl rmvb req_mime_type video/mpeg
reply_body_max_size 10240000 deny  rmvb
非常感谢。
不过这样好像也并不能只阻止电影文件的下载,其他的都一并阻止了。
其实
acl rmvb req_mime_type video/mpeg
这句好像是多余的了,直接用
reply_body_max_size 10240000 deny
任何大于10M的连接都无法下载。


CODE:[Copy to clipboard]ERROR
The requested URL could not be retrieved

--------------------------------------------------------------------------------

While trying to retrieve the URL: ?

The following error was encountered:

The request or reply is too large.
If you are making a POST or PUT request, then your request body (the thing you are trying to upload) is too large. If you are making a GET request, then the reply body (what you are trying to download) is too large. These limits have been established by the Internet Service Provider who operates this cache. Please contact them directly if you feel this is an error.

Your cache administrator is root.

 

--------------------------------------------------------------------------------

Generated Fri, 05 May 2006 03:46:06 GMT by Cachegate (squid/2.5.STABLE12-20051024)
不过这样下来,自己也不能下载10M以上的文件了,是不是只有让自己的80不走squid?还是通过squid让自己绕开这个ACL?

阅读(5001) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~