Denian 12 安装 Squid 及密码、高匿配置指南

Debian 12 and SQUID in a soft color palette with a Japanese style, no octopus or animal images

本指南将详细介绍如何在 Debian 12 上安装 Squid,并进行账号密码和高匿名代理配置。

步骤 1:更新并安装必要的软件包

首先,更新系统并安装所需的软件包:

1
2
sudo apt update
sudo apt install -y curl vim apache2-utils squid

步骤 2:设置 Squid 认证

接下来,为 Squid 创建一个认证文件,并添加一个用户(在这里,用户名为 sd12df):

1
sudo htpasswd -c /etc/squid/passwords username

在提示时输入并确认用户密码。

A 4_3 banner featuring Debian 12 and Squid with a soft color palette and a Japanese style

步骤 3:备份默认的 Squid 配置文件

将默认的 Squid 配置文件备份,以便我们进行修改:

1
sudo mv /etc/squid/squid.conf /etc/squid/squid.conf.original

步骤 4:编辑 Squid 配置文件

使用文本编辑器打开新的 Squid 配置文件:

1
sudo vim /etc/squid/squid.conf

在文件中添加以下内容:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
auth_param basic program /usr/lib/squid/basic_ncsa_auth /etc/squid/passwords
auth_param basic realm Squid proxy-caching web server
auth_param basic credentialsttl 24 hours
auth_param basic casesensitive off
acl authenticated proxy_auth REQUIRED
http_access allow authenticated
http_access deny all
dns_v4_first on
http_port 3128

# 高匿名配置
via off
forwarded_for delete

request_header_access Via deny all
request_header_access X-Forwarded-For deny all
request_header_access From deny all

步骤 5:重启 Squid 服务

保存文件并退出编辑器后,重启 Squid 服务以应用新的配置:

1
sudo service squid restart

检查 Squid 服务状态,确保其正常运行:

1
sudo service squid status

验证

1
curl -x "http://x.x.x.x:3128" --proxy-basic --proxy-user yourusername:yourpassword https://qq.com

IPTABLE 限定

1
2
3
iptables -I INPUT -p tcp --dport 3128 -j DROP
iptables -I INPUT -p tcp -s 127.0.0.1 --dport 3128 -j ACCEPT
iptables -I INPUT -p tcp -s x.x.x.y --dport 3128 -j ACCEPT

总结

通过上述步骤,你可以在 Debian 12 上成功安装并配置 Squid 代理服务器。新的配置不仅支持账号密码认证,还实现了高匿名代理的要求,确保你的代理使用更加安全和隐秘。