squid 添加 用户认证 域名认证

编译参数:添加 --enable-auth=basic' '--enable-basic-auth-helpers=NCSA'

完成后,编译squid.conf

加入:

#定义了认证方式为basic,认证程序的路径和认证程度需要读取的帐户文件

auth_param basic program /usr/lib/squid/ncsa_auth /opt/squid/etc/passwd

#此选项定义了认证程序的进程为5个
auth_param basic children 5

 

#定义了认证程序的时间为2小时,如果2小时过后用户还需要使用squid,则必须重新输入帐户和密码
auth_param basic credentialsttl 2 hours

#定义了用户的登录时显示的领域内容,类似于Apache的用户认证
auth_param basic realm Please input account

 

#指定是否区分用户名大小写,on为区分,off为不区分

auth_param basic casesensitive off

# 强制要求用户验证

acl auth_user proxy_auth REQUIRED

 

#普通用户需要认证才能访问internet,允许经过认证的用户访问。
http_access allow auth_user

 

 

注意:如果有普通用户和高级用户区分的话,http_access应按以下顺序写:

acl  haoyu src  192.168.2.68/32
auth_param basic program /usr/lib/squid/ncsa_auth /opt/squid/etc/passwd
auth_param basic children 5
auth_param basic credentialsttl 2 hours
auth_param basic realm hello

acl auth_user proxy_auth REQUIRED
http_access allow haoyu   (高级用户,不需要验证)
http_access allow auth_user (普通用户,需要验证)

即:在http_access处理过程中,如果先处理auth_user(普通用户),那么当前用户无论haoyu是否属于高级用户,都会被要求进行验证;相反,如果先处理高级用户,那么剩下的就只有需要认证的普通用户了。    


其中/usr/lib/squid/ncsa_auth 和/opt/squid/etc/passwd位置要根据个人设置而定。

ncsa_auth默认安装在/root/squid-3.0.STABLE13/helpers/basic_auth/NCSA/ncsa_auth

我cp 到/usr/lib/squid下。需要读取的帐户文件也需要自己建立,我的是/opt/squid/etc/passwd

然后建立test用户做测试:

/opt/apache/bin/htpasswd -c  /opt/squid/etc/passwd  test

第一次需要加参数c


 

对域名做强行验证,比如要求test.com进行验证,而其他不需要:

acl  test dstdomain  test.com
auth_param basic program /usr/lib64/squid/ncsa_auth /opt/wwwsquid/etc/passwd
auth_param basic children 10
auth_param basic credentialsttl 1 hours
auth_param basic realm hello

acl auth_user proxy_auth REQUIRED
http_access allow !test
http_access allow auth_user

需要直接输入密码时:

htpasswd -bc /opt/wwwsquid/etc/passwd test test
这样对test.com访问时需要做验证,账号:test 密码:test

另一个BT需求,要求只能访问指定域名,并且对其中一个做验证
acl allowdomain  dstdomain pay.com
acl allowdomain  dstdomain test.pay.com
acl allowdomain  dstdomain test.com
http_access deny    !allowdomain

acl  test dstdomain  test.com
auth_param basic program /usr/lib64/squid/ncsa_auth /opt/wwwsquid/etc/passwd
auth_param basic children 10
auth_param basic credentialsttl 1 hours
auth_param basic realm hello

acl auth_user proxy_auth REQUIRED
http_access allow !test
http_access allow auth_user


 

刚刚搭建完成测试成功,估计之后还会出现很多问题,发现了在写吧~~

测试中发现的问题:
我加了以上策略后,不能执行以下命令了?

/opt/squid/bin/squidclient  -p 3128 mgr:info

修改了命令的顺序

acl manager proto cache_object
acl localhost src 127.0.0.1/32
http_access allow manager localhost
acl Purge method PURGE
http_access allow Purge localhost
http_access deny manager
写在用户认证命令的前面,问题解决。

你可能感兴趣的:(添加,squid,休闲,用户认证,域名认证)