部署 Squid 代理服务
启动
-
安装依赖:
sudo apt install squid apache2-utils -
创建密码文件:
sudo htpasswd -c /etc/squid/passwd <username> -
配置 Squid:
sudoedit /etc/squid/conf.d/auth.conf# 认证参数 auth_param basic program /usr/lib/squid/basic_ncsa_auth /etc/squid/passwd auth_param basic realm Squid Proxy Server auth_param basic credentialsttl 2 hours # ACL 定义 acl authenticated proxy_auth REQUIRED # 访问控制 http_access allow localhost manager http_access deny manager http_access allow authenticated http_access deny all -
检查配置:
$ sudo squid -k check 2026/06/03 14:36:21| Processing Configuration File: /etc/squid/squid.conf (depth 0) 2026/06/03 14:36:21| Processing Configuration File: /etc/squid/conf.d/auth.conf (depth 1) 2026/06/03 14:36:21| Processing Configuration File: /etc/squid/conf.d/debian.conf (depth 1) 2026/06/03 14:36:21| Set Current Directory to /var/spool/squid -
重启 Squid 服务
sudo systemctl restart squid
配置 IP 白名单
-
编辑配置文件:
sudoedit /etc/squid/squid.conf# 定义 ACL 规则 acl allowed_ips src 192.168.1.2/32 # 改为本地主机 IP # 定义访问控制规则 http_access allow allowed_ips # 设置代理服务端口 http_port 3128ACL 和访问控制规则需要放到配置文件头部
-
重新加载配置:
sudo squid -k check # 检查配置文件 sudo squid -k reconfigure # 重新加载配置
Troubleshooting
代理服务器拒绝访问请求
诊断方法:
# 检查访问控制规则
grep -E "(acl.*dst|http_access)" /etc/squid/squid.conf | grep -v "^#"
# 检查 Squid 访问日志:
sudo tail -f /var/log/squid/access.log

浙公网安备 33010602011771号