squid配置账号密码认证不生效

squid配置账号密码认证不生效,配置debug也不生效的情况。以下为squid.conf。已经将basic_ncsa_auth复制到了/etc/squid/目录下了。




debug_options ALL,9  88,9  33,9
acl localnet src 10.0.0.0/8     # RFC1918 possible internal network
acl localnet src 172.16.0.0/12  # RFC1918 possible internal network
acl localnet src 192.168.0.0/16 # RFC1918 possible internal network
acl localnet src fc00::/7       # RFC 4193 local private network range
acl localnet src fe80::/10      # RFC 4291 link-local (directly plugged) machines
acl dstnet dst 10.0.0.0/8       #目的地址为内网地址的规则,名称为dstnet
acl dstnet dst 172.16.0.0/16    
acl dstnet dst 192.168.0.0/24
http_access allow dstnet        #放行名称为dstnet的规则
acl SSL_ports port 10022                #定义名称为SSL_ports、类型为port、包含10022端口的规则
acl SSL_ports port 22                   #定义名称为SSL_ports、类型为port、包含22端口的规则
acl SSL_ports port 443                  #定义名称为SSL_ports、类型为port、包含443端口的规则
acl SSL_ports port 80                   #定义名称为SSL_ports、类型为port、包含80端口的规则
acl Safe_ports port 80                  #定义名称为Safe_ports、类型为port、包含80端口的规则
acl Safe_ports port 21                  #定义名称为Safe_ports、类型为port、包含21端口的规则
acl Safe_ports port 443                 #定义名称为Safe_ports、类型为port、包含443端口的规则
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 Safe_ports port 8080
acl Safe_ports port 8081
acl CONNECT method GET POST             #定义名称为CONNECT、类型为method、请求方法包含 GET POST的规则
http_access deny !Safe_ports            #拒绝非Safe_ports规则内的
http_access deny !SSL_ports              #拒绝非SSL_ports规则内的
http_access allow localhost manager
http_access deny manager
http_access allow localnet
http_access allow localhost
auth_param basic program /etc/squid/basic_ncsa_auth /etc/squid/password         #使用/etc/squid/passowrd文件内容进行认证
auth_param basic realm Please enter your account number 
auth_param basic credentialsttl 2 hours                               #认证后状态保持2小时
acl squid_user proxy_auth REQUIRED              #定义授权用户组
http_access allow squid_user                                    #放行授权组
http_access deny all                                            #默认拒绝所有
http_port 3128
coredump_dir /var/spool/squid
debug_options ALL,1 33,2
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 开启认证的配置,可以尝试在最后添加如下配置进行认证:

auth_param basic program /usr/lib/squid3/basic_ncsa_auth /etc/squid3/passwords
acl authenticated proxy_auth REQUIRED
http_access allow authenticated

同时,需要保证 /etc/squid/password 文件的权限设置正确(例如 chmod 400 /etc/squid/password)。另外,建议在调试认证问题时,建议增加常用的调试选项,以便于检查认证情况:

debug_options ALL,1

这样可以在 Squid 的 Access.log 中看到更多的详细信息,例如:

1576219231.613    197 10.0.0.1 TCP_MISS/401 3495 GET http://www.example.com/ - HIER_DIRECT/101.20.21.132 text/html

其中 TCP_MISS/401 表示该请求为未授权,需要认证;HTTP/1.0 401 Unauthorized 表示未授权的详细信息等。

最后,建议查看 Squid 的文档和日志文件以了解更多信息,以帮助您找到并解决具体问题。