需求:允许客户机访问指定的网站,但是允许的网站里面不包括网盘,比如百度相关网站都放行,但是百度网盘不允许访问,其余的所有网站一律不允许访问!
环境:CentOS6.3(64位)
1、安装squid
yum install -y squid
2、squid的主配置文件:
vi /etc/squid/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/12 # RFC1918 possible internal network
#acl localnet src 192.168.0.0/16 # 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) machin
es
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
#
# 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
# And finally deny all other access to this proxy
#http_access deny all
# Squid normally listens to port 3128
http_port 192.168.1.1:3128 ============>监听的IP地址和端口
# We recommend you to use at least the following line.
hierarchy_stoplist cgi-bin ?
# Uncomment and adjust the following to add a disk cache directory.
#cache_dir ufs /var/spool/squid 100 16 256
# 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
dns_nameservers 8.8.8.8 ============>DNS服务器,不能写多个!
允许的网站
acl url_deny url_regex pan.baidu.com
acl url_deny url_regex vdisk.weibo.com
acl url_deny url_regex share.renren.com
acl url_deny url_regex sfsf55.xunzai.com
acl url_deny url_regex disk.sbox.uc.sina.com.cn/webdisk/client
acl url_deny url_regex 163disk.com
http_access deny url_deny
#下面是允许的网站,我之前使用的是-i参数,-i参数是匹配网页里面的关键字!比如我允许放行baidu.com,结果chinaunix的首页里面有百度的关键字也被放行了,所以匹配url不能加-i参数,这里.代表通配符。
acl url_allow url_regex .baidu.com ====>允许百度相关的网站放行,例如www.baidu.com和news.baidu.com
acl url_allow url_regex .bdimg.com ====>一些大网站有自己的图片服务器,例如百度,很多图片都来自于这个服务器,所以得放行。
acl url_allow url_regex .google.com
acl url_allow url_regex .google.cn
acl url_allow url_regex .gstatic.com
acl url_allow url_regex .google-analytics.com
acl url_allow url_regex .googleusercontent.com
acl url_allow url_regex .chinaz.com
acl url_allow url_regex .aizhan.com
acl url_allow url_regex .dedecms.com
acl url_allow url_regex .7c.com
acl url_allow url_regex .ciku5.com
acl url_allow url_regex .bdstatic.com
acl url_allow url_regex .baidustatic.com
acl url_allow url_regex .toberp.com
acl url_allow url_regex .zbintel.com
acl url_allow url_regex .cnzz.com
acl url_allow url_regex .weibo.com
acl url_allow url_regex .weixin.qq.com
acl url_allow url_regex .wx.qq.com
acl url_allow url_regex .renren.com
acl url_allow url_regex .xnimg.cn
acl url_allow url_regex .sinaimg.cn
acl url_allow url_regex .sinajs.cn
acl url_allow url_regex .sina.com.cn
acl url_allow url_regex .youku
acl url_allow url_regex .doubleclick.net
acl url_allow url_regex .ykimg.com
acl url_allow url_regex .iresearch.cn
acl url_allow url_regex .meihua.info
#拒绝所有网站
http_access deny all
3、保存启动squid服务/etc/init.d/squid start
4、开通防火墙3128端口
vi /etc/sysconfig/iptables
-A INPUT -m state --state NEW -m tcp -p tcp -s 192.168.1.0/24 --dport 3128 -j ACCEPT
/etc/init.d/iptables restart
5、客户端测试,在IE里面的工具,局域网里面写上服务器监听的IP地址和端口。这里不详细介绍了!
6、测试成功!