# ...acl allowed_ips src "/etc/squid/allowed_ips.txt"# ...#http_access allow localnethttp_access allow localhosthttp_access allow allowed_ips# And finally deny all other access to this proxyhttp_access deny all
的顺序http_access规则很重要。确保在之前添加该行http_access deny all.
The http_access指令的工作方式与防火墙规则类似。 Squid从上到下读取规则,当一条规则匹配时,下面的规则不被处理。
每当您更改配置文件时,都需要重新启动 Squid 服务才能使更改生效:
sudo systemctl restart squid
鱿鱼认证#
如果基于 IP 限制访问不适用于您的用例,您可以将鱿鱼配置为使用后端来验证用户身份。鱿鱼支持Samba、LDAP 和 HTTP 基本身份验证。
printf"USERNAME:$(openssl passwd -crypt PASSWORD)\n"| sudo tee -a /etc/squid/htpasswd
例如,创建一个用户“josh”,密码为“P@ssvv0rT”,你会运行:
printf "josh:$(openssl passwd -crypt 'P@ssvv0rd')\n" | sudo tee -a /etc/squid/htpasswd
josh:QMxVjdyPchJl6
下一步是启用 HTTP 基本身份验证并将包含用户凭据的文件包含到鱿鱼配置文件中。
打开主配置并添加以下内容:
sudo nano /etc/squid/squid.conf
/etc/squid/squid.conf
# ...auth_param basic program /usr/lib/squid3/basic_ncsa_auth /etc/squid/htpasswdauth_param basic realm proxyacl authenticated proxy_auth REQUIRED# ...#http_access allow localnethttp_access allow localhosthttp_access allow authenticated# And finally deny all other access to this proxyhttp_access deny all