介绍
Squid 是一个功能齐全的缓存代理,支持流行的网络协议,如 HTTP , HTTPS , FTP 等。它可用于通过缓存重复请求,过滤 Web 流量和访问地域限制内容来提高 Web 服务器的性能。
在本教程中,我们将解释如何在 Debian Buster 上设置 Squid 代理。我们还将向您展示如何配置 Firefox 和 Google Chrome 网络浏览器以使用它。
在 Debian 上安装 Squid
Squid 软件包包含在 Debian 10 存储库的标准中。以 sudo 用户身份运行以下命令来安装 Squid :
sudo apt update
sudo apt install squid
安装完成后, Squid 服务将自动启动。
通过检查 Squid 服务的状态来验证安装是否成功并且 Squid 服务是否正在运行:
sudo systemctl status squid
● squid.service - LSB: Squid HTTP Proxy version 3.x
Loaded: loaded (/etc/init.d/squid; generated)
Active: active (running) since Sat 2019-08-03 08:52:47 PDT; 3s ago
...
配置 Squid
可以通过编辑 /etc/squid/squid.conf 配置文件来配置 Squid 。可以使用 “include” 指令包含单独的配置文件。
该 squid.conf 配置文件包含注释描述每个配置选项做什么。
在进行任何更改之前,最好备份原始文件:
sudo cp /etc/squid/squid.conf{,.orginal}
要修改配置,请在文本编辑器中打开文件:
sudo nano /etc/squid/squid.conf
默认情况下, Squid 侦听所有网络接口上的 3128 端口。
如果要更改端口并设置侦听接口,请找到以 http_port 开头的行,并指定接口 IP 地址和新端口。如果没有指定接口, Squid 将监听所有接口。
/etc/squid/squid.conf 中
# Squid normally listens to port 3128
http_port IP_ADDR:PORT
在所有接口和默认端口上运行 Squid 应该适合大多数用户。
访问控制列表 (ACL) 允许您控制客户端访问 Web 资源的方式。默认情况下, Squid 只允许从 localhost 访问。
如果将使用代理的所有客户端都具有静态 IP 地址,则最简单的选项是创建将包含允许的 IP 的 ACL 。
我们将创建一个存储 IP 地址的新包含文件,而不是在主配置文件中添加 IP 地址:
/etc/squid/allowed_ips.txt
192.168.33.1
# All other allowed IPs
完成后,打开主配置文件并创建一个名为 allowed_ips(第一个突出显示的行)的新 ACL ,并允许使用该 http_access 指令(第二个突出显示的行)访问该 ACL :
/etc/squid/squid.conf 中
# ...
acl allowed_ips src "/etc/squid/allowed_ips.txt"
# ...
#http_access allow localnet
http_access allow localhost
http_access allow allowed_ips
# And finally deny all other access to this proxy
http_access deny all
http_access 规则的顺序很重要。请务必最后添加该行 http_access deny all 。
该 http_access 指令的工作方式与防火墙规则类似。 Squid 从上到下读取规则,当规则匹配时,不处理下面的规则。
每当您更改配置文件时,都需要重新启动 Squid 服务才能使更改生效:
sudo systemctl restart squid
Squid 身份验证
Squid 可以使用不同的后端,包括 Samba , LDAP 和 HTTP 基本身份验证。
在这个例子中,我们将配置 Squid 使用基本身份验证。它是 HTTP 协议中内置的简单身份验证方法。
我们将使用该 openssl 实用程序生成密码,并使用以下命令将该 username:password 对附加到 /etc/squid/htpasswd 文件 tee 中:
apt-get install apache2-utils
printf "USERNAME:$(openssl passwd -crypt PASSWORD)\n" | sudo tee -a /etc/squid/htpasswd
让我们创建一个名为 “buster” 的用户,密码为“ Sz$Zdg69” :
printf "buster:$(openssl passwd -crypt 'Sz$Zdg69')\n" | sudo tee -a /etc/squid/htpasswd
buster:RrvgO7NxY86VM
下一步是启用 HTTP 基本身份验证。打开主配置并添=加以下内容:
/etc/squid/squid.conf 中
# ...
auth_param basic program /usr/lib/squid3/basic_ncsa_auth /etc/squid/htpasswd
auth_param basic realm proxy
acl authenticated proxy_auth REQUIRED
# ...
#http_access allow localnet
http_access allow localhost
http_access allow authenticated
# And finally deny all other access to this proxy
http_access deny all
前三个突出显示的行创建一个名为 authenticated 的新 ACL,最后一个突出显示的行允许访问经过身份验证的用户。
重启 Squid 服务:
sudo systemctl restart squid
配置防火墙
UFW 用户可以 3128 通过启用 “Squid” 配置文件来打开端口:
sudo ufw allow 'Squid'
如果使用 nftables 过滤与系统的连接,请通过发出以下命令打开必要的端口:
sudo nft add rule inet filter input tcp dport 3128 ct state new,established counter accept
如果 Squid 在另一个非默认端口上运行,则需要允许该端口上的流量。
文章转载出处
You can definitely see your skills in the article you write. The sector hopes for more passionate writers like you who are not afraid to say how they believe. At all times go after your heart.
This is my first time pay a quick visit at here and i am really pleassant to read everthing at alone place.
能下吗?找了几个不是云盘就是下载不了的
dsadsads
欢迎加入 Typecho 大家族