Squid 是一个开源代理服务器和 Web 缓存守护程序,可拦截和缓存 HTTP、HTTPS、FTP 和其他协议,以提高 Web 性能、减少带宽消耗并增强安全性。
在 Debian 12 书虫上安装 Squid 代理服务器
第 1 步。在我们安装任何软件之前,通过在终端中运行以下命令来确保您的系统是最新的非常重要:apt
<span class="pln">sudo apt update</span>
此命令将刷新存储库,允许您安装最新版本的软件包。
第 2 步。在 Debian 12 上安装 Squid 代理服务器。
在我们继续之前,检查 Squid 软件包在 Debian 12 仓库中是否可用是至关重要的:
<span class="pln">sudo apt search squid</span>
您应该会看到列出的 Squid 包。如果不是,请确保您的存储库配置正确。
现在我们已经确认了 Squid 的可用性,让我们安装它:
<span class="pln">sudo apt install squid</span>
要确保 Squid 在启动时自动启动并立即启动它,请使用以下命令:
<span class="pln">sudo systemctl enable squid sudo systemctl start squid</span>
第 3 步。配置鱿鱼代理服务器。
Squid 的主配置文件是 。此文件是定义 Squid 行为方式的位置。了解其结构至关重要:/etc/squid/squid.conf
<span class="pln">sudo nano </span><span class="pun">/</span><span class="pln">etc</span><span class="pun">/</span><span class="pln">squid</span><span class="pun">/</span><span class="pln">squid</span><span class="pun">.</span><span class="pln">conf</span>
访问控制规则确定谁可以访问您的代理服务器。例:
<span class="pln">acl localnet src </span><span class="lit">192.168</span><span class="pun">.</span><span class="lit">0.0</span><span class="pun">/</span><span class="lit">24</span><span class="pln"> http_access allow localnet</span>
缓存设置会影响 Squid 存储和检索缓存内容的方式。根据您的需要调整这些内容:
<span class="pln">cache_dir ufs </span><span class="pun">/</span><span class="kwd">var</span><span class="pun">/</span><span class="pln">spool</span><span class="pun">/</span><span class="pln">squid </span><span class="lit">100</span> <span class="lit">16</span> <span class="lit">256</span>
您可以自定义错误页面以获得更好的用户体验:
<span class="pln">error_directory </span><span class="pun">/</span><span class="pln">usr</span><span class="pun">/</span><span class="pln">share</span><span class="pun">/</span><span class="pln">squid</span><span class="pun">/</span><span class="pln">errors</span><span class="pun">/</span><span class="pln">en</span>
添加身份验证可增强安全性和控制力:
<span class="pln">auth_param basic program </span><span class="pun">/</span><span class="pln">usr</span><span class="pun">/</span><span class="pln">lib</span><span class="pun">/</span><span class="pln">squid</span><span class="pun">/</span><span class="pln">basic_ncsa_auth </span><span class="pun">/</span><span class="pln">etc</span><span class="pun">/</span><span class="pln">squid</span><span class="pun">/</span><span class="pln">passwd auth_param basic children </span><span class="lit">5</span><span class="pln"> auth_param basic realm </span><span class="typ">Squid</span> <span class="typ">Proxy</span> <span class="typ">Server</span><span class="pln"> auth_param basic credentialsttl </span><span class="lit">2</span><span class="pln"> hours auth_param basic casesensitive off acl auth_users proxy_auth REQUIRED http_access allow auth_users</span>
配置 Squid 后,重新启动服务:
<span class="pln">sudo systemctl restart squid</span>
鱿鱼日志提供了有价值的见解。检查它们:
<span class="pln">tail </span><span class="pun">-</span><span class="pln">f </span><span class="pun">/</span><span class="kwd">var</span><span class="pun">/</span><span class="pln">log</span><span class="pun">/</span><span class="pln">squid</span><span class="pun">/</span><span class="pln">access</span><span class="pun">.</span><span class="pln">log tail </span><span class="pun">-</span><span class="pln">f </span><span class="pun">/</span><span class="kwd">var</span><span class="pun">/</span><span class="pln">log</span><span class="pun">/</span><span class="pln">squid</span><span class="pun">/</span><span class="pln">cache</span><span class="pun">.</span><span class="pln">log</span>
第 4 步。为 Squid 代理服务器配置客户端。
我们将通过配置 Web 浏览器来测试 Squid 代理服务器以使用它。打开您的网络浏览器并转到网络设置。在 Firefox 中,这可以通过转到 来完成。Preferences -> Network Settings
在“网络设置”窗口中,选择“手动代理配置”选项,然后输入 Squid 代理服务器的 IP 地址和之前配置的端口号(在我们的示例中为 8080)。
感谢您使用本教程在 Debian 12 书虫上安装最新版本的 Squid 代理服务器。有关其他帮助或有用信息,我们建议您查看Squid官方网站。