标签:声明 mac nec 好用 following directory nal connect pac
squid是一款高性能的代理缓存服务器,支持FTP、gopher、HTTP协议。
squid一个缓存Internet数据的软件,其接收用户的下载申请(作为代理服务器),并自动处理所下载的数据,并返回给客户。
个人最喜欢的还是squid的正向代理,上网的行为控制很强大。
~]# yum install suqid -y #这里使用yum安装
~]# systemctl enable squid.service #设置开机启动
使用访问控制特性,可以控制在访问时根据特定的时间间隔进行缓存、访问特定站点或一组站点等等。squid访问控制有两个要素:ACL元素
和访问列表
。访问列表可以允许或拒绝某些用户对此服务的访问。
acl acl_element_name type_of_acl_element values_to_acl
注:
常用如下:
访问列表的规则由一些类似allow
或deny
的关键字构成,用以允许或拒绝向特定或一组ACL元素提供服务。
~]# cp /etc/squid/squid.conf{,_bak}
~]# vim /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 #允许目的地址为本机IP
acl allow_domain dstdomain "/etc/squid/allow_domain" #自定义acl(允许目标域名存放在/etc/squid/allow_domain文件中):
# 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 #允许C类网络访问
acl localnet src fc00::/7 # RFC 4193 local private network range
acl localnet src fe80::/10 # RFC 4291 link-local (directly plugged) machines
acl SSL_ports port 443 #允许ssl端口443
acl Safe_ports port 80 # http 允许安全更新的端口为80
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 #请求方法以CONNECT
#
# Recommended minimum Access Permission configuration:
#
# Only allow cachemgr access from localhost
http_access allow allow_domain #只允许allow_domain名称中自定义的域名可访问,在拒绝所有访问
http_access deny all #拒绝所有,当上面没有匹配上,即拒绝所有访问
# 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 #拒绝连接非443端口
# 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 172.23.100.163:3128 #监听在某个IP上的某个端口
# Uncomment and adjust the following to add a disk cache directory.
cache_dir ufs /var/spool/squid 100 16 256 #高速缓存目录 ufs 类型 缓存最在允许100m,16个一级目录,256个二级目录
# Leave coredumps in the first cache dir
coredump_dir /var/spool/squid #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
~]# cat /etc/squid/allow_domain
.npmjs.org
.taobao.org
只允许访问这两具一级域名及所有二级以上域名可访问
~]# squid -k parse //检查配置文件
~]# squid –k rec //重新加载配置文件
~]# squid -zX //初始化缓存目录
~]# vim /etc/sysctl.conf
# Controls IP packet forwarding
net.ipv4.ip_forward = 1 #打开本地转发
~]# sysctl -p //重新加载配置文件,使其生效
~]# systemct start squid.service
~]# ss -tnl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 :::22 :::*
LISTEN 0 128 *:22 *:*
LISTEN 0 128 172.23.100.163:3128 *:*
LISTEN 0 100 ::1:25 :::*
LISTEN 0 100 127.0.0.1:25 *:*
squid做正向代理实在是非常好用。推荐使用。
此笔记中只做了域名访问控制,没有使用其它例如,用户认证,时间控制、限制URL、禁止IP等功能。如后期用上,则在做补充。
如有错误,欢迎指出。
标签:声明 mac nec 好用 following directory nal connect pac
原文地址:https://www.cnblogs.com/dance-walter/p/9432260.html