acl,禁止资源访问,squid


squid禁用mp4规则:
 acl mp4_url url_regex -i \.mp4$
http_access deny mp4_url
===============
http://guanjianfeng.com/archives/322923

利用squid的acl控制语句来控制某些站点的访问,前几天在网络改造时一直没有成功。在squid.conf中acl字段如下:

acl web src 192.168.20.0/24
http_access allow web 
acl badsite dstdomain 17lele.com 
acl badurl url_regex -i sex
http_access deny badsite
http_access deny badurl
acl all src 0.0.0.0/0.0.0.0
http_access deny all

今天刚看了CNFUG十六期Horus的一篇文章–在FreeBSD上安装Squid,才再次去试着改一下,最后明白:上次我是装禁止站点的语句加在了

acl web src 192.168.20.0/24
http_access allow web

的后面,所以就省略了我新加的这两句。所以我将badsite和badurl字段的两句放到前面,重启,成功禁止了17lele.com和带sex字段的网址。如下:

acl badsite dstdomain 17lele.com 
acl badurl url_regex -i sex
http_access deny badsite
http_access deny badurl
acl web src 192.168.20.0/24
http_access allow web 
acl all src 0.0.0.0/0.0.0.0
http_access deny all

 

附上acl语句详细说明:

ACL,Access Control List,访问控制列表.它的语法是: (在/usr/local/squid/etc/squid.conf里添加) 
acl 表名 表类型 [-i] 表的值
http_access [allow/deny] 表名下面分条解释:
表名:可以自定义
表类型:表类型有
src 源地址:客户机的IP地址
dst 目的地址:服务器的IP地址
srcdomain 源域:客户机所属的域
dstdomain 目的域:服务器所属的域 
url_regex URL正则表达式(字符串部分)
urlpath_regex URL正则表达式中的路径
time [星期] [时间段]
maxconn 客户端的最大连接数
-i 这个参数使Squid不区分大小写
表的值:随表的类型不同而不同
注意:time中的星期要用如下字符:
S (Sunday,星期日) M(Monday,星期一) T(Tuesday,星期二) W(Wednesday,星期三)
H(Thursday,星期四) F(Friday,星期五) A(Saturday,星期六)
时间段的表示方式是: XX:00-YY:00 如: 20:00-22:00
http_access 选项允许你设置一个表是允许(allow)还是拒绝(deny)
下面举几个例子: 防3721的ACL.在squid.conf中加入: 
acl badurls dstdomain -i www.3721.com www.3721.net download.3721.com cnsmin.3721.com
http_access deny badurls
acl badkeywords url_regex -i 3721.com 3721.net
http_access deny badkeywords
解释: 
badurls 和 badkeywords 是你自定义的表名. 
dstdomain 是服务器的域名(目的域) 而 url_regex 则是URL正则表达式(字符串部分)包含的内容. 
http_access 选项的 deny 则是把表badurls和表badkeywords的访问拒绝. 
禁止下载Flash: 
acl badfiles urlpath_regex -i .swf$ 
http_access deny badfiles
大家在今后的配置中,慢慢体会ACL的用法吧! 达到目的喽: 
错误 
您所请求的网址(URL)无法获取 
——————————————————————————–
当尝试读取以下网址(URL)时: 
http://www.3721.com/ 发生了下列的错误: 
Access Denied. 拒绝访问 
Access control configuration prevents your request from being allowed at this time. Please contact your service provider if you feel this is incorrect. 当前的存取控制设定禁止您的请求被接受,如果您觉得这是错误的,请与您网路服务的提供者联系。 本缓存服务器管理员:guanjianfeng@jscpu.com

 

附上acl语句详细说明:

ACL,Access Control List,访问控制列表.它的语法是: (在/usr/local/squid/etc/squid.conf里添加) 
acl 表名 表类型 [-i] 表的值
http_access [allow/deny] 表名下面分条解释:
表名:可以自定义
表类型:表类型有
src 源地址:客户机的IP地址
dst 目的地址:服务器的IP地址
srcdomain 源域:客户机所属的域
dstdomain 目的域:服务器所属的域 
url_regex URL正则表达式(字符串部分)
urlpath_regex URL正则表达式中的路径
time [星期] [时间段]
maxconn 客户端的最大连接数
-i 这个参数使Squid不区分大小写
表的值:随表的类型不同而不同
注意:time中的星期要用如下字符:
S (Sunday,星期日) M(Monday,星期一) T(Tuesday,星期二) W(Wednesday,星期三)
H(Thursday,星期四) F(Friday,星期五) A(Saturday,星期六)
时间段的表示方式是: XX:00-YY:00 如: 20:00-22:00
http_access 选项允许你设置一个表是允许(allow)还是拒绝(deny)
下面举几个例子: 防3721的ACL.在squid.conf中加入: 
acl badurls dstdomain -i www.3721.com www.3721.net download.3721.com cnsmin.3721.com
http_access deny badurls
acl badkeywords url_regex -i 3721.com 3721.net
http_access deny badkeywords
解释: 
badurls 和 badkeywords 是你自定义的表名. 
dstdomain 是服务器的域名(目的域) 而 url_regex 则是URL正则表达式(字符串部分)包含的内容. 
http_access 选项的 deny 则是把表badurls和表badkeywords的访问拒绝. 
禁止下载Flash: 
acl badfiles urlpath_regex -i .swf$ 
http_access deny badfiles
大家在今后的配置中,慢慢体会ACL的用法吧! 达到目的喽: 
错误 
您所请求的网址(URL)无法获取 
——————————————————————————–
当尝试读取以下网址(URL)时: 
http://www.3721.com/ 发生了下列的错误: 
Access Denied. 拒绝访问 
Access control configuration prevents your request from being allowed at this time. Please contact your service provider if you feel this is incorrect. 当前的存取控制设定禁止您的请求被接受,如果您觉得这是错误的,请与您网路服务的提供者联系。 本缓存服务器管理员:guanjianfeng@jscpu.com

 
=====================
http://qubaoquan.blog.51cto.com/1246748/292605

RedHat linux 系统默认已经安装了squid 
1.squid代理服务的配置

有以下最基本的设置squid就可以启动使用了

http_port 192.168.0.110:8080

cache_mem 64 MB

cache_dir ufs /var/spool/squid 4096 16 256

cache_effective_user squid

cache_effective_group squid

dns_nameservers 192.168.0.1

cache_access_log /var/log/squid/access.log

cache_log /var/log/squid/cache.log

cache_store_log /var/log/squid/store.log

visible_hostname 192.168.0.110

cache_mgr qubaoquan@ccpower.com.cn

acl all src 0.0.0.0/0.0.0.0

http_access allow all

1.1 指定squid服务器监听的ip和端口

http_port 192.168.0.110:8080

1.2 设置内存缓冲的大小(仅仅用于共享上网设为物理内存的1/2,如果还有其他服务责不应超过物理内存的1/3

cache_mem 64 MB

1.3 设置内存盘缓冲的大小

cache_dir ufs /var/spool/squid 4096 16 256

Ufs 是指缓冲的存贮类型,/var/spool/squid是存贮目录,4096代表最大存贮空间,16代表一级存贮目录,256代表二级存贮目录

1.4 设置使用存贮的有效用户和组

cache_effective_user squid

cache_effective_group squid

1.5 定义DNS服务器地址

\ dns_nameservers 192.168.0.1

1.6 设置访问日志文件

cache_access_log /var/log/squid/access.log

1.7 设置缓存日志文件

cache_log /var/log/squid/cache.log

1.8 设置网页缓冲日志文件

cache_store_log /var/log/squid/store.log

1.9 设置运行squid主机的名称

visible_hostname 192.168.0.110

1.10 设置管理员邮件地址

cache_mgr qubaoquan@ccpower.com.cn

1.11 设置默认的访问控制列表

acl all src 0.0.0.0/0.0.0.0

http_access allow all

2.初始化squid /usr/sbin/squid –z(创建squid在硬盘缓冲区的目录结构)

3.访问控制列表

类型选项

命令

说明

src

IP地址(客户机IP地址)

dst

目标IP地址(服务器IP地址)

srcdomain

源名称(客户机所属的域)

dstdomain

目标名称(服务器所属的域)

time

一天中的时刻和一周内的一天

url_regex

URL规则表达式匹配

urlpath_regex:url-path

略去协议和主机名的URL规则表达式匹配

proxy_auth

通过外部程序进行用户认证

maxconn

单一IP的最大连接数

time

语法为:时间 时间段 星期可用首字母大写表示,时间段可表示为:1100-2000

 

列表语法:acl 列表名称 列表类型 –i 列表值

http_access allow/deny 列表名称

实际应用举例

(1) 禁止IP地址为192.168.16.200的客户机上网

acl test src 192.168.16.200

http_access deny test

(2) 禁止192.168.1.0这个网段里的所有客户机上网

acl test src 192.168.1.0/255.255.255.0

http_access deny test

http_access deny test

(3) 禁止用户访问IP210.21.118.68的网站

acl test dst 210.21,118.68

http_access deny test

(4) 禁止用户访问域名为www.163.com的网站

acl test dstdomain –i www.163.com

http_access deny test

(5) 禁止用户访问域名包含有163.com的网站

acl test url_regex –i 163.com

http_access deny test

(6) 禁止用户访问包含有sex关键字的URL

acl test url_regex –i sex

http_access deny test

(7) 限制IP地址为192.168.16.200的客户机并发的最大连接数为5

acl test src 192.168.16.200

acl test2 maxconn 5

http_access deny test test2

(8) 禁止192.168.2.0这个子网里所以客户机在周一至周五的9点到18点上网

acl test src 192.168.2.0 /255.255.255.0

acl test2 time MTWHF 900-1800

http_access deny test test2

(9) 禁止用户下载*.mp3,*.exe,*.zip,*.rar

acl test urlpath_regex –i \.mp3$\.exe$\.zip$\.rar$

http_access deny test

(10) 禁止QQ通过squid上网

acl test url_regex –i tencent.com

http_access deny test

注:启动squid/etc/init.d/squid start

停止squid /etc/init.d/squid stop

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

重新导入配置文件 /etc/init.d/squid reload

4.透明代理的实现

1实现透明代理的语句(vi /etc/squid/squid.conf

http_accel_host virtual

http_accel_port 80

http_accel_with_proxy 0n

httpd_accel_uses_host_header 0n

http_accel_hosthttp_accel_port来定义squid的加速模式,virtual是虚拟主机模式,80为请求的端口

http_accel_with_proxy 选项定义为on后,squid既是web请求的加速器又是缓存代理服务器

httpd_accel_uses_host_header定义为on后,在透明代理模式下代理服务器的缓存功能才能工作

2设置端口重定向

iptables –t nat –A PREROUTING -s 192.168.1.0/24 -p tcp --dport 80 -j REDIRECT --to-ports 8080

(3) 重新导入配置文件 /etc/init.d/squid reload

配置用户身份验证

1. 配置/etc/squid/squid.conf(NCSA认证)

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 Example.com's Squid proxy-caching

acl auth_user proxy_auth REQUIRED

http_access allow auth_user

auth_param basic program选项定义了认证方式为basic/usr/lib/squid/ncsa_auth /etc/squid/passwd定义了认证程序的路径和读取的账户文件

auth_param basic children 定义了认证程序的进程数

auth_param basic credentialsttl 定义了经过认证后的有效时间

auth_param basic realm 定义了WEB 浏览器显示输入用户/密码对话框的领域内容

acl auth_user proxy_auth REQUIREDhttp_access allow auth_user设置合法用户的访问控制列表

2. 建立账户文件

htpasswd -c /etc/squid/passswd test(建第一个用户时要用-c选项)

htpasswd /etc/squid/passswd test2

htpasswd /etc/squid/passswd test3

3. 重新启动squid服务

 

http://tanxin.blog.51cto.com/6114226/1254878

Squid三种代理方式的实现及ACL

操作环境:(Redh5.8)

Client:192.168.8.70          (如图:机器为8.70)

Squid:192.168.8.71(eth0)   (如图:机器为8.71)

      172.16.1.16(eth1)   (如图: 机器为8.72)

Web:  172.16.1.17

图:

(注:实验过程中涉及的dns相关内容没有做)

Squid的主要功能:

1.支持HTTP,FTP协议

2.采用层次化缓存结构

3.支持代理SSL

4.实现了ICP(Internet缓存协议,HTCP(超文本缓存协议)等)

5.支持透明代理

6.支持WCCP(Web缓存通信协议)

7.支持丰富的访问控制列表功能

8.支持HTTP加速功能,实现反向代理

9.支持SNMP

10.支持缓存DNS查询

 

一.正向代理(标准代理)

 

 1. 一个标准的代理缓冲服务被用于缓存静态的网页(例如:html文件和图片文件等)到本地网络上的一台主机上(即代理服务器)。当被缓存的页 面被第二次访问的时候,浏览器将直接从本地代理服务器那里获取请求数据而不再向原web站点请求数据。这样就节省了宝贵的网络带宽,而且提高了访问速度。

2. 访问过程(如上图)

@1.客户端使用某一端口连接代理服务器3128端口,请求web页面(连接的网卡为eth0)


@2.代理服务器向DNS请求得到相应的IP地址,然后,代理服务器使用某一端口,向该IP地址的80端口发起web连接请求,请求web页面。(连接的网卡为eht1)

@3.~@5收到响应的web页面后,代理服务器把该数据传送给客户端。并查看自己有没有缓存,若没有缓存一份


@6.~@7.当客户端再次访问时,直接通过缓存返给客户端信息

3.具体配置

(1)装包

[root@tx2 ~]# yum install -y squid

(2)开启包转发

[root@tx2 ~]# vim /etc/sysctl.conf

net.ipv4.ip_forward = 1

 

(3)修改配置文件

[root@tx2 ~]# vim /etc/squid/squid.conf

637  http_access allow all         //给所有的客户端开启代理服务

921  http_port 192.168.8.71:3128     //设置squid监听的端口//192.168.8.71的ip是squid与客户端链接的网卡的ip地址。

1579 cache_mem 8 MB     设定squid占用的物理内存,一般为物理内存的1/3(代表squid能使用多少内存,如果你的内存足够可以调的稍微大一些)

 

1786 cache_dir ufs /var/spool/squid 100 16 256  设定缓存的位置

       @1.ufs  :同步,有请求过来先把得到的数据写入磁盘再处理请求

       @2.aufs :异步,先响应请求再把数据写入磁盘

       @3.100  :M,缓存的数据大小

       @4.16   :1级子目录的数量

       @5.256  :2级子目录的数量

1842    cache_swap_low 90   最低“水位线“

//95:代表cache 占用swap的空间最多是百分之95,如果大于百分之95,squid会自动删除之前保存的数据

 

1843 cache_swap_high 95  最高“水位线“

//90: 代表删除的时候还是会保存最新的百分之90

 

2974 cache_effective_user squid  通知系统是以squid用户的身份去执行

 

4. 配置web端的http服务

 

#yum install -y httpd

#cd /var//ww/html

#echo “helo tx” > index.html

#/etc/init.d/httpd start

 

5. 配置client端的浏览器

@1.点击edit,然后点击edit下的Preferences

@2.点击Advanced----->Network-------->Settings

@3.如图所示

配置完成

 

6.client端测试

二.Squid的透明代理

 1.透明代理缓冲服务和标准代理服务器的功能完全相同。但是,代理操作对客户端的浏览器是透明的(即不需指明代理服务器的IP和端口)。透明代 理服务器阻断网络通信,并且过滤出访问外部的HTTP(80端口)流量。如果客户端的请求在本地有缓冲则将缓冲的数据直接发给用户,如果在本地没有缓冲则 向远程web服务器发出请求,其余操作和标准的代理服务器完全相同。

  2访问过程

@1.客户端向DNS请求,得到相应的IP地址。然后,客户端使用某一端口,向该IP地址的80端口发起web连接请求,请求web页面。


@2~@3.当该请求包通过透明代理服务器时,被防火墙将该数据包重定向到代理服务器的绑定端口3128。于是,透明代理服务器用某一端口发起web连接请求,请求web页面。


@4~@5收到响应的web页面后,代理服务器把该数据传送给客户端。并查看自己有没有缓存,若没有缓存一份


@6.~@7.当客户端再次访问时,直接通过缓存返给客户端信息

 

3.具体配置

(1)修改配置文件

[root@tx2 ~]# vim /etc/squid/squid.conf

http_port 192.168.8.71:3128 transparent

(2)配置防火墙规则

[root@tx2 ~]# iptables -t nat -A PREROUTING -s 192.168.0.0/24 -p tcp --dport 80 -j REDIRECT --to-port 3128

//所有192.168.0.0这个网段访问squid的80端口,都由防火墙转发到3128的squid服务端口

 

[root@tx2 ~]# iptables -t nat -L

Chain PREROUTING (policy ACCEPT)

target     prot opt source               destination        

REDIRECT   tcp  --  192.168.0.0/24       anywhere            tcp dpt:http redir ports 3128

 

Chain POSTROUTING (policy ACCEPT)

target     prot opt source               destination        

 

Chain OUTPUT (policy ACCEPT)

target     prot opt source               destination        

[root@tx2 ~]# iptables -t nat -F

[root@tx2 ~]# service squid restart

Stopping squid: ................                           [  OK  ]

Starting squid: .                                          [  OK  ]

(3)客户端取消代理

(4)配置客户端网观

[root@tx1 ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0

添加GATEWAY=“squid的ip”

[root@tx1 ~]# /etc/init.d/network restart

(5)测试

三.反向代理(web加速)

    1.反向代理是和前两种代理完全不同的一种代理服务。使用它可以降低原始WEB服务器的负载。反向代理服务器承担了对原始WEB服务器的静态页 面的请求,防止原始服务器过载。

2.访问过程

@1.客户端通过浏览器向DNS服务器发送请求,由客户所在地的DNS服务器解析IP地址,并将结果返回给用户。


@2.客户收到DNS返回的服务器IP地址,重新向DNS服务器指向的IP地址发送访问请求。

 

@3.squid 服务器接收到用户的请求后,查询自身缓存中是否有用户请求内容,有则直接发送给客户端

@4. 有则通过内部DNS轮询查询空闲服务器,并将客户请求发送到 该服务器,在获取到用户数据并返回给用户的同时保留一份在自己本身的缓存当中。

 

在用户看来,自己访问的是www.96333.com这个服务器,实际上真 正的WEB服务器为SQUID缓存后面的服务器或者服务器集群,通过外部DNS做CNAME转向,将用户请求转发到内部真正的web服务器上去。

 

3.具体配置

(1)[root@tx2 ~]# vim /etc/squid/squid.conf

923 http_port 80 transparent

924 cache_peer 172.16.1.17 parent 80 0 originserver no-query name= www

originserver 源点服务器

no-query     不询问

name=www     用来区分相似的查询

(其他选项不变)

(2)测试

四.访问控制(ACL)

1.ACL元素

语法定义如下:

acl aclname acltype string1

acl aclname acltype "file"

//acltype可以是(src、dst、srcdomain、dstdomain、url_regex、urlpath_regex、time、port、proto、method)

 

(1) src:源地址。定义如下:

acl aclname src ip-address/netmask ... 客户ip地址

acl:aclname src addr1-addr2/netmask ... 地址范围

 

(2)dst:目标地址

acl aclname dst ip-address/netmask ...

 

(3)srcdomain:客户所属的域

acl aclname srcdomain foo.com ...

 

(4)dstdomain:请求服务器所属的域

acl aclname dstdomain foo.com ...

 

(5)time:访问时间

acl aclname time [day-abbrevs] [h1:m1-h2:m2][hh:mm-hh:mm]

1 S:指代Sunday

2 M:指代Monday

3 T:指代Tuesday

4 W:指代Wednesday

5 H:指代Thursday

6 F:指代Friday

7 A:指代Saturday

 

(6)port:访问端口。可以指定多个端口

acl aclname port 80 70 21 ...

acl aclname port 0-1024 ... 指定一个端口范围

 

(7)proto:使用协议

acl aclname proto HTTP FTP ...

 

(8)method:请求方法

acl aclname method GET POST ...

 

(9)url_regex:URL规则表达式匹配

acl aclname url_regex[-i] pattern

 

(10)urlpath_regex:URL-path规则表达式匹配

acl aclname urlpath_regex[-i] pattern

 

2.http_access访问控制列表

根据访问控制列表允许或禁止某一类用户访问。最后的条目设为“deny all”或“allow all”来避免安全性隐患。http_access Action声明1 AND 声明2 AND多个,http_access声明间用或运算连接,但每个访问条目的元素间用与运算连接,列表中的规则总是遵循由上而下的顺序。

3.实例应用

(1)禁止IP地址为192.168.8.200的客户机上网

acl client src 172.16.1.2

http_access deny client

 

(2)禁止网段10-50上网

 

acl client src 172.16.1.10-172.16.1.50/32

http_access deny client

 

(3)拒绝访问web的ip

acl client dst 192.168.1.2

http_access deny client

 

(4)限制URL以 某些内容 开头

acl client url_regex index

http_access deny client

 

(5)限制URL 以 某些内容 结尾

 

acl client urlpath_regex \.html

http_access deny client

 

(6)限制时间段

acl client time MTWHFA 9:00-18:00

http_access deny client

 

(7)限制443端口上网

acl http port 443

http_access deny http

 

(8)限制用户并发连接数为:5

acl clientsrc 172.16.1.15

acl conn5 max 5

http_access deny client conn5

 

(9)禁止下载*.mp3$ *.exe$ *.zip$ *.rar$ *.doc$类型的文件

acl client  urlpath_regex -i \.mp3$ \.exe$ \.zip$ \.rar$ \.doc$

http_access deny client

注:这些访问控制可以根据实际情况加到上面的三种代理方式中,访问控制要写的有意义

本文出自 “tanxin” 博客,请务必保留此出处http://tanxin.blog.51cto.com/6114226/1254878

 

 

http://bbs.51cto.com/archiver/tid-1094430.html

squid服务器里的ACL控制没起作用...

squid.conf



#
# Recommended minimum configuration:
#
acl manager proto cache_object
acl localhost src 127.0.0.1/32 ::1
acl to_localhost dst 127.0.0.0/8 0.0.0.0/32 ::1

# Example rule allowing access from your local networks.
# Adapt to list your (internal) IP networks from where browsing
# should be allowed
acl localnet src 10.0.0.0/8 # RFC1918 possible internal network
acl localnet src 172.16.0.0/16 # RFC1918 possible internal network
acl localnet src 192.168.10.0/24 # RFC1918 possible internal network
acl localnet src fc00::/7 # RFC 4193 local private network range
acl localnet src fe80::/10 # RFC 4291 link-local (directly plugged) machines

acl pm_equipment src "/etc/squid/ip_server"
#acl pm_qiantai src "/etc/squid/ip_special"  #设置内网IP列表
#acl pm_backup src "/etc/squid/ip_limited"   #设置内网IP列表 
acl pm-dhcp src "/etc/squid/ip_dhcp"
acl deny_ip dst "/etc/squid/deny_ip"
#设置禁止访问外网的IP
acl deny_dns dstdomain "/etc/squid/deny_dns"
#设置禁止访问的域名
#acl deny_urlpath urlpath_regex -i \.bmp$ \.png$ \.jpg$ \.gif$ \.jpeg$
acl deny_urlpath urlpath_regex -i "/etc/squid/deny_urlpath"
#设置禁止访问包含关键字的url,如:\.jpg$
acl deny_url url_regex -i "/etc/squid/deny_url"
#设置禁止访问的url,如^">http://
acl deny_urlhead dstdom_regex -i "/etc/squid/deny_urlhead"
#设置禁止访问某些关键字开头的网址,如:^game
acl deny_downfile url_regex -i "/etc/squid/deny_downfile"
#设置禁止下载的文件类型,如:\.mp3$ \.vbs$ \.rmvb$
acl server_time time SMTWHFA 01:00-24:00
#设置服务器连网时间 



acl SSL_ports port 443
acl Safe_ports port 80 # http
acl Safe_ports port 21 # ftp
acl Safe_ports port 443 # https
acl Safe_ports port 70 # gopher
acl Safe_ports port 210 # wais
acl Safe_ports port 1025-65535 # unregistered ports
acl Safe_ports port 280 # http-mgmt
acl Safe_ports port 488 # gss-http
acl Safe_ports port 591 # filemaker
acl Safe_ports port 777 # multiling http
acl CONNECT method CONNECT


acl pmfsip src 192.168.10.240
acl pmfsmac arp 00:0C:29:CE:EC:5F
http_access deny pmfsmac !pmfsip
http_access deny !pmfsmac pmfsip


#
# Recommended minimum Access Permission configuration:
#
# Only allow cachemgr access from localhost
http_access allow manager localhost
http_access deny manager

# Deny requests to certain unsafe ports
http_access deny !Safe_ports

# Deny CONNECT to other than secure SSL ports
http_access deny CONNECT !SSL_ports

# We strongly recommend the following be uncommented to protect innocent
# web applications running on the proxy server who think the only
# one who can access services on "localhost" is a local user
http_access deny to_localhost

#
# INSERT YOUR OWN RULE(S) HERE TO ALLOW ACCESS FROM YOUR CLIENTS
#

# Example rule allowing access from your local networks.
# Adapt localnet in the ACL section to list your (internal) IP networks
# from where browsing should be allowed
http_access allow localnet
http_access allow localhost
#允许特殊用户使用443端口,但不能上网
#http_access allow pm_qiantai SSL_ports
#服务器上网时间
http_access allow pm_equipment server_time
http_access deny deny_ip
http_access deny deny_dns
http_access deny deny_url
http_access deny deny_urlpath !all
http_access deny deny_downfile
http_access deny deny_urlhead
http_access allow pm-dhcp




# And finally deny all other access to this proxy
http_access allow all

# Squid normally listens to port 3128
http_port 192.168.10.240:8080 transparent

# We recommend you to use at least the following line.
hierarchy_stoplist cgi-bin ?




# Leave coredumps in the first cache dir
coredump_dir /var/spool/squid

# Add any of your own refresh_pattern entries above these.
refresh_pattern ^ftp:        1440    20%    10080
refresh_pattern ^gopher:    1440    0%    1440
refresh_pattern -i (/cgi-bin/|\?) 0    0%    0
refresh_pattern .        0    20%    4320


#禁止缓存  URL中有包含cgi-bin和https:\\开头的都不缓存,asp、cgi、php等动态脚本不缓存
hierarchy_stoplist -i ^https:\\ ?                               
hierarchy_stoplist cgi-bin ?
acl QUERY urlpath_regex -i cgi-bin \? \.asp \.php \.jsp \.cgi
acl denyssl urlpath_regex -i ^https:\\
no_cache deny QUERY
no_cache deny denyssl

# Uncomment and adjust the following to add a disk cache directory.
cache_dir ufs /var/spool/squid 2048 16 256


#设置硬盘缓冲位置大小存储类型,注意:加粗的这个值一定要比cache_mem大,不然会报错。
cache_mem 1024 MB #指定缓冲内存大小(根据服务器配置以及需要来配置,一般设置1/3-1/2倍的内存大小即可)
cache_swap_low 90 #最低缓存率百分比
cache_swap_high 95 #最高缓存率百分比,当高速缓存占用到95%时,自动减小到90%
maximum_object_size 4096 KB #设置squid磁盘缓存最大文件,超过4M的文件不保存到硬盘
minimum_object_size 0 KB #设置squid磁盘缓存最小文件
maximum_object_size_in_memory 4096 KB #设置squid内存缓存最大文件,超过4M的文件不保存到内存

#dns_children 10  #设置DNS查询程序的进程数,默认是5,据说最高是32
redirect_children 100 #指定squid应该开启多少重定向进程,默认值是5个进程
ipcache_size 1024  #DNS解析后的IP放在缓存中,可免去重复查询DNS,提高访问速度
ipcache_low 90
ipcache_high 95
fqdncache_size 1024

#设置主机名
visible_hostname pmproxy
#设置报错为中文
error_directory /usr/share/squid/errors/zh-cn
#设置访问日志
cache_access_log /var/log/squid/access.log  
    
cache_log /var/log/squid/cache.log
#设置缓存日志
logfile_rotate 6 
#设置日志轮转,6表示会生成0~6共7个日志文件
cache_mgr [email=admin@ojc.com]admin@admin.com[/email]
#设置管理员邮箱
forwarded_for off  
#不传递被代理地址      
via off
#不传递代理服务器信息



deny_urlpath
\.jpg$


deny_dns
[url=www.baidu.com]www.baidu.com[/url]
[url=www.sina.com.cn]www.sina.com.cn[/url]


虚拟机两个网卡
内网192.168.10.240
外网172.16.10.240


另一个虚拟机IP设置为
192.168.10.241
255.255.255.0
192.168.10.240

DNS
192.168.10.240

可这台机还是能访问baidu,sina,和下载图片...
不知哪里设置有问题了,请教各位大大. 

 

 

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM