1.yum install -y squid
正向代理设置:
2.编辑配置文件,加入以下配置信息
#vi /etc/squid/squid.conf
http_port 3128
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
acl localnet src 10.0.0.0/8
acl localnet src 172.16.0.0/12
acl localnet src 192.168.0.0/16 # RFC1918 possible internal network
acl SSL_ports port 443
acl Safe_ports port 80 8080
acl Safe_ports port 21
acl Safe_ports port 443
acl CONNECT method CONNECT
http_access allow manager localhost
http_access deny manager
http_access deny !Safe_ports
http_access deny CONNECT !SSL_ports
http_access allow localnet
http_access allow localhost
http_access allow all
cache_dir aufs /data/cache 1024 16 256
cache_mem 128 MB
hierarchy_stoplist cgi-bin ?
coredump_dir /var/spool/squid
refresh_pattern ^ftp:
refresh_pattern ^gopher:
refresh_pattern -i (/cgi-bin/|\?) 0
refresh_pattern \.(jpg|png|gif|mp3|xml) 1440
refresh_pattern .
3.#mkdir
#chown -R squid:squid /data/cache
#squid -z
#/etc/init.d/squid start
#squid
#squid -k rec #可以重新加载配置
#service squid restart #重启squid服务
4.测试
curl -xlocalhost:3128 www.qq.com
curl -xlocalhost:3128 www.baidu.com
acl bad_domain dstdomain .sina.com .souhu.com
http_access allow http !bad_domain
http_access deny http bad_domain
acl good_domain dstdomain .lishiming.net .aminglinux.com
http_access allow http good_domain
http_access deny http !good_domain
cache_peer 61.135.169.125 parent 80 0 originserver name=b
cache_peer_domain a www.qq.com
cache_peer_domain b www.baidu.com
后面连cache_peer_domain 也省了。
重启squid服务测试:
#/etc/squid/squid.conf restart
#curl -xlocalhost:80 www.baidu.com
会出现一大段信息,表示测试成功,能够访问此网站。
本文由 Mr Gu 创作,采用 知识共享署名4.0 国际许可协议进行许可
本站文章除注明转载/出处外,均为本站原创或翻译,转载前请务必署名
最后编辑时间为: Aug 26, 2016 at 09:24 pm