- squid访问控制
- acl元素类型
- src:源地址(即客户机IP地址)
- dst:目的地址(即服务器IP地址)
- srcdomain:源名称(即客户机名称)
- dstdomain:目的名称(即服务器名称)
- time:一天中的时刻和一周内的一天
- url_regex: URL规则表达式匹配
- urlpath_regex:URL-path规则表达式匹配
- proxy_auth:通过外部程序进行用户验证
- maxconn:单一IP的最大连接数
- 访问条目
- http_access:允许HTTP访问
- no_cache:定义对缓存请求的响应
- 常用几种acl列表类型
列表类型 列表内容示例 含义/用途 src 192.168.1.168/32 192.168.1.0/255.255.255.0 192.168.1.0-192.168.3.0/24 客户端的 IP 地址或网络段、地址范围 dst www.playboy.com 216.163.137.3/32 用户访问的目标主机名或者 IP 地址 port 80 8000 8080 21 用户访问的目标端口 srcdomain .benet.com .accp.com 客户端来源域(根据 IP 地址作反向解析) dstdomain .benet.com .accp.com 用户访问的目标域,匹配域内所有站点 time MTWHF 8:30-17.30 12:00-1300 AS 用户上网的时间段 字母表示一星期中各天的英文缩写 M-Monday、T-Tuesday W-Wednesday、H-Thursday、F-Friday A-Saturday、S-Sunday maxconn 15 客户端的并发 HTTP 连接数 url_regex url_regex -i ^rtsp://^mms:// url_regex -i ^emule:// 用户访问的整个 URL 网址,可以使用正则表达式, 加-i 表示忽略大小写 urlpath_regex urlpath_regex -i sex adult nude urlpath_regex -i \.mp3$\.rar$ 匹配用户访问的 URL 路径(部分),可以使用正则 表达式 - 设置acl访问权限,http_access
http_access allow |deny [!] aclname
- acl元素类型
- 搭建squid
auth_param basic program /usr/lib64/squid/basic_ncsa_auth /etc/squid/passwd-file #设置用户名和密码 auth_param basic children 5 #启动5个进程 auth_param basic realm Zhumu's proxy-only server #客户端连接squid代理显示内容 auth_param basic credentialsttl 5 hours ##认证有效时间 acl localnet src 10.10.0.0/20 # 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) machines acl SSL_ports port 443 #定义SSL_ports为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 800-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 For url_regex 10.10.25.210:8443 #目标URL地址 acl For url_regex 10.10.25.210:9443 #目标URL地址 acl CONNECT method CONNECT #定义CONNECT代表http里的CONNECT请求方法 acl zhumu proxy_auth REQUIRED #定义认证的用户 http_access allow zhumu http_access deny !Safe_ports #拒绝不安全端口请求 http_access deny CONNECT !SSL_ports #不允许连接非安全SSL_ports端口 http_access allow localhost manager #允许本地访问squid中的manager功能 http_access deny manager #禁止访问manager功能 http_access allow localnet #允许局域网用户的请求 http_access allow localhost #允许局域网用户的请求 http_access deny all #拒绝其他所有请求 http_access deny For #拒绝访问目的URL地址 http_port 10080 #Squid的监听端口 coredump_dir /var/spool/squid #核心启动文件保存的缓存目录 maximum_object_size 4096KB #最大缓存块 maximum_object_size_in_memory 10 MB #内存缓存 reply_body_max_size 1024000 allow all #限定下载文件大小 #缓存数据的存储格式 缓存目录 缓存目录占磁盘空间大小 缓存空间一级子目录个数 缓存空间二级子目录个数 cache_dir ufs /var/spool/squid 100 16 256 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
htpasswd -c /etc/squid/passwd-file test