我想在 Ubuntu 22.04 中使用 squid 代理阻止下载 .doc、.dat、.mp3、.wav、.avi .rar、.exe 等文件,但无法做到,已经尝试了许多带有 urlpath_regex 参数的选项。示例如下:-
acl block_exe url_regex .*\.exe$
http_access deny block_exe
------------------------
Blocking file types in squid
First of all, create an ACL file includes all the file types to block downloading them.
[root@server ~]# vi /etc/squid/bad_files.acl
\.[Ee][Xx][Ee]$ #block downloading exe executable files
\.[Mm][Pp]3 $ #Block mp3 music files
\.[Zz][Ii][Pp]$ #Block ZIP archive files
\.[Jj][Pp][Ee][Gg]$ #Block jpeg picture files
\.[Aa][Vv][Ii]$ #Block avi video files
\.[Tt][Oo][Rr][Rr][Ee][Nn][Tt]$ #Block torrent files
#(Add the above required file extensions types and save the file)
然后,编辑 squid 配置文件并为上面创建的 acl 文件添加 ACL。
acl badfiles urlpath_regex "/etc/squid/bad_files.acl" (ACL for blocked file types)
http_access deny badfiles lan (Deny the file types to lan)
#(Add the above three lines and save the squid.conf file)