前言
Squid Cache(简称为Squid)是HTTP代理服务器软件。Squid用途广泛,可以作为缓存服务器,可以过滤流量帮助网络安全,也可以作为代理服务器链中的一环,向上级代理转发数据或直接连接互联网。(维基百科)
通过Squid实现Linux的HTTP代理服务器
服务端
下载依赖
MacOS
Linux
Debian
CentOS
配置账户(可选)
下载依赖
- 下载 apache httpd 使用 htpasswd 工具生成密码
Linux
Debian
生成身份认证文件
/etc/squid/passwd:指定生成的身份认证文件
1
| htpasswd -c /etc/squid/passwd <username>
|
1 2 3
| New password: Re-type new password: Adding password for user <username>
|
备份默认配置文件(可选)
1
| cp /etc/squid/squid.conf /etc/squid/squid.conf.default
|
修改配置文件
无身份校验
3128:定义服务端监听端口
<ip>:定义允许连接的客户端IP地址
1 2 3 4 5
| acl localnet src <ip>/32 acl localnet src <ip>/32 http_access allow localnet
http_port 3128
|
有身份校验
/etc/squid/passwd:身份认证文件路径
1 2 3 4 5 6 7 8 9
| auth_param basic program /usr/lib/squid/basic_ncsa_auth /etc/squid/passwd auth_param basic realm proxy auth_param basic children 50 auth_param basic credentialsttl 2 hours acl authenticated proxy_auth REQUIRED http_access allow authenticated http_access deny all
http_port 3128
|
重启服务
客户端
无身份认证
<ip>:服务端IP地址
3128:服务端端口号
1 2
| export https_proxy=http://<ip>:3128 export http_proxy=http://<ip>:3128
|
有身份认证
<username>:用户名
<password>:密码
1 2
| export https_proxy=http://<username>@<password>:<ip>:3128 export http_proxy=http://<username>@<password>:<ip>:3128
|
完成
参考文献
草凡的博客
博客园——SSgeek