squid正向代理,就是本地发起的http连接,先经过squid代理,再连到web网站。如果squid缓存有相同网页,就直接发给浏览器,这样就减轻了带宽压力。
安装
Centos:
#yum install squid
debian/Ubuntu:
#apt install squid3
添加用户
useradd -M squid -s /sbin/nologin
我的正向代理配置
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
#拒绝所有不需要的端口的连接
http_access deny !Safe_ports
#https加密连接只连接443
http_access deny CONNECT !SSL_ports
http_access allow localhost manager
http_access deny manager
http_access allow localhost
http_access deny all
coredump_dir /var/spool/squid3
#最小缓存时间 网页剩余有效时间的百分之几 最大缓存时间
refresh_pattern ^ftp: 1440 20% 10080
refresh_pattern ^gopher: 1440 0% 1440
refresh_pattern -i (/cgi-bin/|\?) 0 0% 0
#忽略网页重载
refresh_pattern -i .(jpg|png|gif|webp|jpeg|bmp|mp3|wma|wmv|xml|doc|docx|swf) 1440 50% 28800 ignore-reload
#未修改就不重载
refresh_pattern -i .(css|js) 60 50% 1440 reload-into-ims
refresh_pattern . 0 20% 4320
hierarchy_stoplist cgi-bin ?
coredump_dir /var/spool/squid
#代理端口
http_port 127.0.0.1:3128
#内存限制
cache_mem 512 MB
#设置squid用户及用户组、管理员账号
cache_effective_user squid
cache_effective_group squid
#缓存目录 容量MB 父文件夹数 子文件夹数
cache_dir ufs /usr/share/squid3/cache 10240 32 256
#最低swap与最高swap %
cache_swap_low 90
cache_swap_high 95
#日志目录
cache_access_log /usr/share/squid3/logs/access.log
cache_log /usr/share/squid3/logs/cache.log
cache_store_log /usr/share/squid3/logs/store.log
#缓存错误联系邮箱
cache_mgr lxbian@localhost
visible_hostname Windows8
#最大单个文件
maximum_object_size 10 MB
#内存中最大单个文件
maximum_object_size_in_memory 2 MB
测试配置
centos:
squid -k check /etc/squid/squid.conf
debian:
squid3 -k check /etc/squid/squid.conf
初始化
centos:
squid -z
debian:
squid3 -z
启动
centos:
squid
debian:
squid3
测试是否启动
curl -xlocalhost:3128 http://www.baidu.com -I
启动成功后,就可以在浏览器里设置代理了,ip地址是127.0.0.1,port端口是3128