Squid:修订间差异
无编辑摘要 |
(→快速开始) |
||
第11行: | 第11行: | ||
==快速开始== | ==快速开始== | ||
配置一个匿名代理 | |||
1.编辑squid配置文件<code>sudo vim /etc/squid/squid.conf</code> | |||
<syntaxhighlight lang="bash" > | |||
# 设置监听端口,也可以使用常用端口(如 80 或 443) | |||
http_port 22001 | |||
# 禁用客户端 IP 转发 | |||
forwarded_for off | |||
# 隐藏代理标识 | |||
via off | |||
# 伪装 HTTP 请求,不暴露自身版本信息 | |||
httpd_suppress_version_string on | |||
# 不通过系统的 DNS 查询 | |||
dns_nameservers 8.8.8.8 8.8.4.4 | |||
# 允许所有ip访问,建议设置认证(如用户名密码) | |||
acl all src 0.0.0.0/0 | |||
http_access allow all | |||
# 添加用户名密码认证 | |||
# htpasswd 工具通常包含在 Apache2 工具包中。安装sudo apt install apache2-utils | |||
# 创建用户名和密码:sudo htpasswd -c /etc/squid/passwd 用户名 | |||
auth_param basic program /usr/lib/squid/basic_ncsa_auth /etc/squid/passwd | |||
acl authenticated proxy_auth REQUIRED | |||
http_access allow authenticated | |||
http_access deny all | |||
# 禁用日志或定期清理 | |||
access_log none | |||
</syntaxhighlight> | |||
2.重启Squid 服务 | |||
<syntaxhighlight lang="bash" > | |||
# 重启Squid | |||
sudo systemctl restart squid | |||
# 检查是否运行正常 | |||
sudo systemctl status squid | |||
</syntaxhighlight> | |||
3.测试,可以使用多种方法 | |||
*1. 浏览器设置 | |||
*2. 系统代理设置 | |||
*3. 应用程序设置 | |||
curl工具示例 | |||
<syntaxhighlight lang="bash" > | |||
curl --proxy http://127.0.0.1:22001 http://httpbin.org/headers | |||
# 如果配置了认证 | |||
curl --proxy-user 用户名:密码 --proxy http://127.0.0.1:22001 https://httpbin.org/ip | |||
</syntaxhighlight> | |||
==通信== | ==通信== |
2025年2月23日 (日) 09:33的版本
Squid是一个开源的web缓存代理服务器软件。专门设计用来缓存 Web 内容、控制访问权限、提高性能、减少带宽消耗。它是专门用于做 HTTP/HTTPS 代理,并且支持访问控制列表 (ACL),认证,日志记录等特性。
简介
时间轴
安装
在 Ubuntu/Debian 系统上,可以通过以下命令安装:
sudo apt update
sudo apt install squid
快速开始
配置一个匿名代理
1.编辑squid配置文件sudo vim /etc/squid/squid.conf
# 设置监听端口,也可以使用常用端口(如 80 或 443)
http_port 22001
# 禁用客户端 IP 转发
forwarded_for off
# 隐藏代理标识
via off
# 伪装 HTTP 请求,不暴露自身版本信息
httpd_suppress_version_string on
# 不通过系统的 DNS 查询
dns_nameservers 8.8.8.8 8.8.4.4
# 允许所有ip访问,建议设置认证(如用户名密码)
acl all src 0.0.0.0/0
http_access allow all
# 添加用户名密码认证
# htpasswd 工具通常包含在 Apache2 工具包中。安装sudo apt install apache2-utils
# 创建用户名和密码:sudo htpasswd -c /etc/squid/passwd 用户名
auth_param basic program /usr/lib/squid/basic_ncsa_auth /etc/squid/passwd
acl authenticated proxy_auth REQUIRED
http_access allow authenticated
http_access deny all
# 禁用日志或定期清理
access_log none
2.重启Squid 服务
# 重启Squid
sudo systemctl restart squid
# 检查是否运行正常
sudo systemctl status squid
3.测试,可以使用多种方法
- 1. 浏览器设置
- 2. 系统代理设置
- 3. 应用程序设置
curl工具示例
curl --proxy http://127.0.0.1:22001 http://httpbin.org/headers
# 如果配置了认证
curl --proxy-user 用户名:密码 --proxy http://127.0.0.1:22001 https://httpbin.org/ip
通信
Squid 支持的通信方式
协议 | 描述 |
---|---|
HTTP | 最常用的协议,客户端通过 HTTP 协议向 Squid 发送请求,Squid 转发请求到目标服务器。 |
HTTPS | 支持客户端与 Squid 之间的加密通信,Squid 转发 HTTPS 请求到目标服务器。可配置 SSL 证书进行加密。 |
SSL Bump | 通过中间人方式解密 HTTPS 流量进行监控或内容过滤,通常用于透明代理或流量分析。 |
FTP | Squid 作为 FTP 代理,客户端通过代理访问 FTP 服务器。 |
Gopher | Squid 支持 Gopher 协议,尽管现代互联网使用较少,但 Squid 仍然提供此支持。 |
Transparent Proxy (透明代理) | Squid 作为透明代理,客户端无需手动配置,所有流量都自动通过代理服务器转发。 |
ICP (Internet Cache Protocol) | Squid 通过 ICP 与其他 Squid 缓存服务器通信,优化缓存性能。 |
资源
官网
- Squid官网:https://www.squid-cache.org/
- Squid文档:https://www.squid-cache.org/Doc/
- Squid源代码 https://github.com/squid-cache/squid/