squid3正向代理

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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值