1.下载
wget https://github.com/squid-cache/squid/archive/refs/tags/SQUID_7_6.tar.gz
tar zxf SQUID_7_6.tar.gz
cd squid-SQUID_7_6/
2.编译安装
创建用户/组
useradd -r -s /sbin/nologin squid
安装 bootstrap 依赖(生成 configure 必需) 在 squid-SQUID_7_6 目录下执行
./bootstrap.sh
#下载最新的config.sub/config.guess(适配AlmaLinux 9/10.1)
wget -O cfgaux/config.sub https://git.savannah.gnu.org/cgit/config.git/plain/config.sub
wget -O cfgaux/config.guess https://git.savannah.gnu.org/cgit/config.git/plain/config.guess
chmod +x cfgaux/config.sub cfgaux/config.guess
编译
./configure \
--prefix=/opt/squid \
--sysconfdir=/opt/squid/etc \
--with-default-user=squid \
--with-openssl \
--with-epoll \
--enable-basic-auth-helpers=NCSA \
--enable-storeio=ufs \
--enable-ssl-crtd
make -j 1 && make install
安装htpasswd工具
dnf install -y httpd-tools
chown -Rf squid:squid /opt/squid
htpasswd -c /opt/squid/etc/passwd user
chown squid:squid /opt/squid/etc/passwd
chmod 600 /opt/squid/etc/passwd
启动squid
/opt/squid/sbin/squid -k reconfigure
/opt/squid/sbin/squid -k parse
/opt/squid/sbin/squid -z
/opt/squid/sbin/squid -N -d1
3.关键配置说明
auth_param basic program /usr/lib64/squid/basic_ncsa_auth
调用 squid 自带的basic_ncsa_auth程序读取 htpasswd 格式密码文件;
auth_param basic credentialsttl 2 hours:客户端认证缓存 2 小时,2 小时后重新输密码;
acl authenticated proxy_auth REQUIRED:判定必须通过账号密码;
http_access allow authenticated:任意来源 IP,只要密码正确就放行代理(正向代理);
完整squid.conf配置文件如下:
acl localnet src 0.0.0.1-0.255.255.255 # RFC 1122 "this" network (LAN)
acl localnet src 10.0.0.0/8 # RFC 1918 local private network (LAN)
acl localnet src 100.64.0.0/10 # RFC 6598 shared address space (CGN)
acl localnet src 169.254.0.0/16 # RFC 3927 link-local (directly plugged) machines
acl localnet src 172.16.0.0/12 # RFC 1918 local private network (LAN)
acl localnet src 192.168.0.0/16 # RFC 1918 local private network (LAN)
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
auth_param basic program /opt/squid/libexec/basic_ncsa_auth /opt/squid/etc/passwd
auth_param basic children 5
auth_param basic realm "Please input proxy username and password"
auth_param basic credentialsttl 2 hours
auth_param basic casesensitive off
acl authenticated proxy_auth REQUIRED
http_access deny !Safe_ports
http_access deny CONNECT !SSL_ports
http_access allow localhost manager
http_access deny manager
http_access allow localhost
http_access allow authenticated
http_access deny to_localhost
http_access deny to_linklocal
http_access deny all
http_port 3128
coredump_dir /opt/squid/var/cache/squid
refresh_pattern ^ftp: 1440 20% 10080
refresh_pattern -i (/cgi-bin/|\?) 0 0% 0
refresh_pattern . 0 20% 4320