Squid 是一个代理和缓存服务器,它将请求转发到所需的目的地,同时保存请求的内容,当你再次请求相同内容时,他可以向你提供缓冲内容,从而提高访问速度。Squid代理服务器目前支持的协议有:http、SSL、DNS、FTP。
一:安装Squid
1、更新您的系统软件包
apt update && sudo apt upgrade -y
2、安装policy代理
apt-cache policy squid
3、启动代理,并设置
apt install -y squid
systemctl start squid
systemctl enable squid
systemctl status squid

二:配置Squid代理
1、备份Squid配置文件
cp /etc/squid/squid.conf /etc/squid/squid.conf.bk
2、编辑squid.conf
vim /etc/squid/squid.conf
3、修改代理端口
在squid.conf中查找http_port 3128

默认端口为3128,你可以修改为任意你想使用的端口,假如你只是希望自己私密使用,你可以选一个别从比较难找到的端口。
4、放通防火墙设置
ufw allow 8080/tcp
ufw enable
如未开启防火墙此步可省略。
5、设置Squid缓存大小
cache_mem 256 MB

6、配置使用的DNS
dns_nameservers 8.8.8.8 8.8.4.4

7、设置ACL访问和http access
设置acl,在squid.conf里面查找下面,并配置或添加。

设置http access访问,想出去的就allow,不想让出去的就deny。

以上配置就基本上配置好了。接下来重启squid服务
systemctl restart squid
三:划重点
1、屏蔽 Squid 代理服务器上的传出流量,关闭via on
# via on
via off
2、去掉代理标头
request_header_access From deny all
request_header_access Server deny all
request_header_access WWW-Authenticate deny all
request_header_access Link deny all
request_header_access Cache-Control deny all
request_header_access Proxy-Connection deny all
request_header_access X-Cache deny all
request_header_access X-Cache-Lookup deny all
request_header_access X-Forwarded-For deny all
request_header_access Pragma deny all
request_header_access Keep-Alive deny all
3、设置访问密码
设置一个名为test的用户访问密码
touch /etc/squid/passwd
chown proxy: /etc/squid/passwd
htpasswd /etc/squid/passwd test
编辑squid.conf,添加如下代码,以启用密码服务。
auth_param basic program /usr/lib/squid/basic_ncsa_auth /etc/squid/passwd
auth_param basic children 5
auth_param basic realm Squid Basic Authentication
auth_param basic credentialsttl 2 hours
acl auth_users proxy_auth REQUIRED
http_access allow auth_users
4、调试
显示配置文件中的错误
squid -k parse
显示auth的正确位置
dpkg -L squid | grep ncsa_auth
四:访问端设置
打开win11的设置,找到"网络和Internet",然后是"代理"

找到手动设置代理,如下图

在这里填上你刚才的Squid服务器IP和访问商品就配置好啦。