实战记录——Centos使用squid搭建带用户认证的高匿HTTP代理服务

1.安装相关包

带用户认证需要用到httpd-tool

yum install -y squid httpd-tool

2.生成密码文件

使用 htpasswd 命令生成密码文件,默认是MD5的格式,可以用选项改其他格式

命令格式:
htpasswd [选项] 文件名 用户名

常用选项
-c 创建新文件,如果没加此选项会把新增的用户添加在末尾
-2 SHA-256格式的密码
-5 SHA-512格式的密码
-B bcrypt格式的密码
-d CRYPT格式的密码
-s SHA-1格式的密码

示例:

htpasswd /etc/squid/passwd test

3.配置squid

打开配置文件

vim /etc/squid/squid.conf

***注意:先把其他http_access注释掉,很重要***

用户认证添加以下配置,
auth_param basic program /usr/lib64/squid/basic_ncsa_auth /etc/squid/passwd #用户验证使用模块
auth_param basic children 5	#可同时验证数量
auth_param basic realm test #连接提示文本
auth_param basic credentialsttl 1 days #认证有效期,这里也可以改成小时
acl users proxy_auth REQUIRED #用户认证
http_access allow users #通过认证的允许访问
http_access deny all #默认拒绝

其中basic_ncsa_auth模块不一定同位置可以自己查看位置在哪
rpm -ql squid |grep ncsa

高匿添加配置
request_header_access Via deny all
request_header_access X-Forwarded-For deny all

可选关闭缓存和隐藏缓存请求头
acl denyssl method GET
no_cache deny denyssl

request_header_access Server deny all
request_header_access X-Cache deny all
request_header_access X-Cache-Lookup deny all

开放端口
http_port 3128 #3128是默认记得修改

测试时使用的配置文件


acl localnet src 0.0.0.1-0.255.255.255

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

access_log /var/log/squid/access.log
acl denyssl method GET
no_cache deny denyssl

auth_param basic program /usr/lib64/squid/basic_ncsa_auth /etc/squid/passwd
auth_param basic children 5
auth_param basic realm test
auth_param basic credentialsttl 1 days
acl users proxy_auth REQUIRED
http_access allow users
http_access deny all

request_header_access Via deny all
request_header_access X-Forwarded-For deny all
request_header_access Server deny all
request_header_access X-Cache deny all
request_header_access X-Cache-Lookup deny all

http_port 23128

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 .		0	20%	4320

使用命令检查配置,没问题启动即可
squid -k parse
systemctl start squid

关闭时建议使用
squid -k shutdown

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值