如何在 Ubuntu 上设置带密码保护的 Elite HTTP Squid 代理?

How do I setup an Elite HTTP Squid Proxy with password protection on Ubuntu?

我想设置一个 Elite HTTP 代理。一个 Elite proxy should not expose any information about the source to the destination address. I have hired a Ubuntu virtual private server for this purpose. The proxy should be password protected, so that only I can use it. I would like to use Squid 作为我的代理人。

实现这一目标的步骤是什么?

更新您的 APT 存储库并安装我们需要的软件

sudo apt-get update
sudo apt-get install squid3
sudo apt-get install apache2-utils

Squid3是代理软件。 htpasswd 需要 apache2-utils,我们将其用作平面文件密码存储来保护代理。

设置密码存储

sudo touch /etc/squid/passwords
sudo chmod 777 /etc/squid/passwords
sudo htpasswd -c /etc/squid/passwords USERNAME
[prompt for new password]

在上面的行中,将 USERNAME 替换为您希望在代理上使用的用户名。执行该行时,系统会提示您输入用户密码。

测试密码存储

/usr/lib/squid3/basic_ncsa_auth /etc/squid/passwords

执行此行后,控制台看起来像挂起,有一个没有任何文本的提示。输入 "USERNAME PASSWORD"(将其替换为您的特定用户名和密码)并点击 return。您应该会收到响应 "OK"。如果不是,请查看错误消息,您的 username/password 可能不正确。它也可能 basic_ncsa_auth 位于不同的路径(例如 lib64)。

配置 Squid 代理

移动默认的 squid 配置文件

sudo mv /etc/squid/squid.conf /etc/squid/squid.conf.original

现在创建一个新的squid配置文件

vi /etc/squid/squid.conf

应该是这样的

http_port 3128
dns_v4_first on
cache deny all
forwarded_for delete
tcp_outgoing_address 9.9.9.9   //-- change this ip
via off
auth_param basic program /usr/lib/squid3/basic_ncsa_auth /etc/squid/passwords
auth_param basic realm proxy
acl authenticated proxy_auth REQUIRED
http_access allow authenticated
http_access deny all

下面是对每一行的作用的描述:

  • http_port:指定代理监听端口。这是必需的
  • dns_v4_first on:有效关闭 IPv6 DNS。如果没有这个,您的代理可能 运行 非常 缓慢。
  • cache deny all: 停止代理缓存页面
  • forwarded_for 删除:删除 forwarded_for http header 这会将您的源暴露给目标
  • tcp_outgoing_address:将此设置为您的服务器地址。您可以使用命令 "ip a"
  • 找到地址
  • via off: 删除更多 headers 这会暴露你的来源
  • auth_param:定义您创建的 basic_ncsa_auth 和密码文件的位置。请注意,您可能需要检查 basic_ncsa_auth.
  • 的位置
  • acl authenticated:为通过密码存储验证的用户创建访问控制列表
  • http_access allow authenticated: 允许用户通过密码验证后访问代理
  • http_access全部拒绝:如果您没有通过密码验证,您将无法进入

重启squid代理

service squid restart

注意该服务也可以称为 squid3。代理重启可能需要一段时间。如果您愿意,可以使用命令

重新加载 squid 配置
squid -k reconfigure

检查其工作情况

service squid status

服务应该是运行ning。

netstat -ltnp

您应该会看到一个服务正在侦听端口 3128,或者您在配置中使用的任何端口。

在您的桌面上,打开 firefox,转到选项-> 网络代理 -> 设置。选择使用手动代理配置。在 HTTP 代理字段中输入您服务器的 IP 地址,并在端口字段中包含端口。单击确定。

转到google,出现提示时输入您的用户名和密码,搜索"what is my ip address",您应该会看到您的代理服务器的IP。