1.安装环境
sudo apt install openssh-server
sudo apt install apache2-utils
sudo apt install squid
2.安全起见,设置服务器密码
sudo htpasswd -c /etc/squid/passwd 用户名
# 输入两次明文密码,会自动生成passwd文件,共代理服务鉴权验证使用
3.修改配置文件
cd /etc/squid/
sudo cp squid.conf squid.conf.bak
sudo rm -rf /etc/squid/squid.conf
sudo vi /etc/squid/squid.conf
可以直接用下图配置
acl SSL_ports port 443
acl Safe_ports port 80 # http
acl Safe_ports port 21 # ftp
acl Safe_ports port 443 # https
acl Safe_ports port 70 # gopher
acl Safe_ports port 210 # wais
acl Safe_ports port 1025-65535 # unregistered ports
acl Safe_ports port 280 # http-mgmt
acl Safe_ports port 488 # gss-http
acl Safe_ports port 591 # filemaker
acl Safe_ports port 777 # multiling http
acl CONNECT method CONNECT
# 注意此处路径具体为/usr/lib64还是/usr/lib视具体情况而定
# 查找指令为 sudo find / -name basic_ncsa_auth
auth_param basic program /usr/lib/squid/basic_ncsa_auth /etc/squid/passwd
acl auth_user proxy_auth REQUIRED
http_access allow auth_user
http_access deny !Safe_ports
http_access deny CONNECT !SSL_ports
http_access deny all
http_port 3128
coredump_dir /var/spool/squid
refresh_pattern ^ftp: 1440 20% 10080
refresh_pattern ^gopher: 1440 0% 1440
refresh_pattern -i (/cgi-bin/|\?) 0 0% 0
refresh_pattern (Release|Packages(.gz)*)$ 0 20% 2880
refresh_pattern . 0 20% 4320
request_header_access X-Forwarded-For deny all
request_header_access From deny all
request_header_access Via deny all
四.启动代理服务器
sudo squid -z # 初始化缓存文件,选用项,有时出现问题很玄学
sudo service squid start
sudo service squid status 查看启动是否成功
如果提示服务已启动,可以重启服务
sudo service squid restart