Squid实现用户名密码,使用HTTPBasicAuth 的方式

squid  

Squid实现用户名密码,使用HTTPBasicAuth 的方式。

安装Squid

yum install squid -y  

需要htpasswd工具来创建passwd文件

yum install -y httpd  

创建用户proxy_username 的命令如下:

htpasswd  -c /etc/squid/passwd proxy_username  
输入相应的密码后,生成 文件 /etc/squid/passwd

将下述代码添加到/etc/squid/squid.conf 中即配置实用验证的功能:

auth_param basic program /usr/lib64/squid/basic_ncsa_auth /etc/squid/passwd  
acl auth_user proxy_auth REQUIRED  
http_access allow auth_user  
  • 贴个完整的配置
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 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  
http_access deny !Safe_ports  
http_access deny CONNECT !SSL_ports  
http_access allow localhost manager  
http_access deny manager  
http_access allow localnet  
http_access allow localhost

# 只改动这里
auth_param basic program /usr/lib64/squid/basic_ncsa_auth /etc/squid/passwd  
acl auth_user proxy_auth REQUIRED  
http_access allow auth_user

http_access deny all  
# 端口建议变动 
http_port 31282

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 的安装文件会自带,需要 正确的路径, Squid 3.8的文件是 :

/usr/lib64/squid/basic_ncsa_auth

重启squid,使用命令,即可实现为Squid代理服务器添加用户名密码验证的功能。:

service squid restart 或  
/etc/init.d/squid restart