安装
yum -y install squid
配置文件
[root@locvps ~]# cat /etc/squid/squid.conf
# 允许所有主机使用squid
acl localnet src all
# 允许使用端口 443 进行 SSL/TLS 安全连接。
acl SSL_ports port 443
# 允许使用端口 80 进行 HTTP 访问
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
# 充分支持CONNECT方法,这使得用户能够建立到目标服务器的隧道连接。
acl CONNECT method CONNECT
# 监听端口
http_port 65532
# 核心转储日志目录
coredump_dir /var/spool/squid
# basic 认证文件
auth_param basic program /usr/lib64/squid/basic_ncsa_auth /etc/squid/passwd
# basic 认证线程 5 个
auth_param basic children 5
# basic 认证提示信息
auth_param basic realm "Please user auth!"
# basic 认证超时时间
auth_param basic credentialsttl 24 hours
# basic 认证访问规则
acl authenticated proxy_auth REQUIRED
# basic 允许 localnet 来源进行认证
http_access allow localnet authenticated
# 拒绝其他访问 本句话需要放在认证最后 否则会报禁止访问
http_access deny all
# 缓存刷新策略
refresh_pattern ^ftp: 1440 20% 10080
refresh_pattern ^gopher: 1440 0% 1440
refresh_pattern -i (/cgi-bin/|\?) 0 0% 0
refresh_pattern . 0 20% 4320
htpasswd 生成用户名密码文件
htpasswd -c /etc/squid/passwd pub
# 交互输入密码
测试
curl -x xxx.xxx.xxx.xxx:65532 -U admin:admin http://f64.cc
curl -x admin:admin@xxx.xxx.xxx.xxx:65532 http://f64.cc