如果要在squid中加入用户名和密码的验证,使用NCSA是最方便的:
-
生成用户名,密码文件
用命令 htpasswd 来生成,使用非常简单,生成一个叫passwdfile的密码文件,包含username和password账户:
htpasswd -bc passwdfile username password
添加username和password账户到passwdfile中
htpasswd -b passwdfile username password
-
配置squid.conf
#使用ncsa_auth程序命令使用.passwd账号文件验证
auth_param basic program /usr/lib/squid/ncsa_auth /etc/squid/.passwd
#最大并发验证程序数
auth_param basic children 5
#验证数据库刷新时间(多长时间去看一下.passwd文件是否发生变化)
auth_param basic credentialsttl 2 hours
#说明auth_user是需要进行验证才能通过的
acl auth_user proxy_auth REQUIRED
在这里要注意到squid访问规则的意义:找到符合条件的就停止,于是以下两条是不同的:
http_access allow auth_user
http_access deny all
和
http_access allow otheruser
http_access allow auth_user
http_access dene all
后者的otheruser不需要经过验证就可以使用squid缓存,因为在验证之前就匹配了
运行后不同点在:
多了5个验证程序