/etc/squid/squid.conflinux
定義語法:安全
acl aclname acltype string服務器
acl aclname acltype "file"網站
src 定義來源地址 (即用戶的客戶機IP地址);ui
acl aclname src ip-address/netmaskurl
acl aclname src addr1-addr2/netmaskspa
dst定義目標地址 (即用戶請求的網站IP地址):代理
acl aclname dst ip-address/netmaskip
port用於指定訪問端口string
acl aclname port 80 1024
acl aclname port 0-1024
url-regex 用於限制網址中的關鍵詞:
acl aclname url_regex [-i] pattern
proto 用於定義要代理的協議:
acl aclname proto HTTP FTP
method 用於制定請求的方法:
acl aclname method GET POST
訪問控制列表有多個規則條目組成,根據指定的條件來容許或限制訪問請求,匹配順序會由上至下,一旦匹配則當即結束,一般會在控制列表的最下面寫上 " deny all " 或者 " allow all " 來避免安全隱患。
實戰操做:
僅容許192.168.0.10的主機使用本篤 Squid 服務 ,拒絕其他主機
acl client src 192.168.0.10
http_access allow client
http_access deny all
拒絕客戶機使用代理服務器訪問帶有關鍵詞 " linux " 的網站
acl deny_keyword url_regex -i linux
http_access deny deny_keyword
拒絕客戶機使用代理服務器訪問 " 京東 " 網站
acl deny_url url_regex https://www.jd.com
http_access deny deny_url
禁止客戶機代理服務器下載 MP3 與 rar 爲後綴的文件
acl badfile urlpath_regex -i \.mp3$ \.rar$
http_access deny badfile