Ubuntu24.X 搭建Squid 代理(http及https)

本文内容在ubuntu24.04下验证完毕,直接使用的root账号,2024年10月10日

squid是一款类似于nginx的代理软件,可以用于搭建代理服务器。
我使用nginx主要用来做反向代理,squid用于做正向代理相较于nginx更为方便。

1.安装

直接使用命令进行安装

apt install squid

2.查看安装结果

squid --version

执行结果如下,可以看到当前安装版本,为6.6版本,该版本相较于博主之前用的3.X版本,配置上有很多不同

root@ubuntu:~# squid --version
Squid Cache: Version 6.6
Service Name: squid
Ubuntu linux

This binary uses OpenSSL 3.0.13 30 Jan 2024. configure options:  '--build=x86_64-linux-gnu' '--prefix=/usr' '--includedir=${prefix}/include' '--mandir=${prefix}/share/man' '--infodir=${prefix}/share/info' '--sysconfdir=/etc' '--localstatedir=/var' '--disable-option-checking' '--disable-silent-rules' '--libdir=${prefix}/lib/x86_64-linux-gnu' '--runstatedir=/run' '--disable-maintainer-mode' '--disable-dependency-tracking' 'BUILDCXXFLAGS=-g -O2 -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -ffile-prefix-map=/build/squid-CDRpf1/squid-6.6=. -flto=auto -ffat-lto-objects -fstack-protector-strong -fstack-clash-protection -Wformat -Werror=format-security -fcf-protection -fdebug-prefix-map=/build/squid-CDRpf1/squid-6.6=/usr/src/squid-6.6-1ubuntu5.1 -Wno-error=deprecated-declarations -Wdate-time -D_FORTIFY_SOURCE=3 -Wl,-Bsymbolic-functions -flto=auto -ffat-lto-objects -Wl,-z,relro -Wl,-z,now ' 'BUILDCXX=g++' '--with-build-environment=default' '--enable-build-info=Ubuntu linux' '--datadir=/usr/share/squid' '--sysconfdir=/etc/squid' '--libexecdir=/usr/lib/squid' '--mandir=/usr/share/man' '--enable-inline' '--disable-arch-native' '--enable-async-io=8' '--enable-storeio=ufs,aufs,diskd,rock' '--enable-removal-policies=lru,heap' '--enable-delay-pools' '--enable-cache-digests' '--enable-icap-client' '--enable-follow-x-forwarded-for' '--enable-auth-basic=DB,fake,getpwnam,LDAP,NCSA,PAM,POP3,RADIUS,SASL,SMB' '--enable-auth-digest=file,LDAP' '--enable-auth-negotiate=kerberos,wrapper' '--enable-auth-ntlm=fake,SMB_LM' '--enable-external-acl-helpers=file_userip,kerberos_ldap_group,LDAP_group,session,SQL_session,time_quota,unix_group,wbinfo_group' '--enable-security-cert-validators=fake' '--enable-storeid-rewrite-helpers=file' '--enable-url-rewrite-helpers=fake' '--enable-eui' '--enable-esi' '--enable-icmp' '--enable-zph-qos' '--enable-ecap' '--disable-translation' '--with-swapdir=/var/spool/squid' '--with-logdir=/var/log/squid' '--with-pidfile=/run/squid.pid' '--with-filedescriptors=65536' '--with-large-files' '--with-default-user=proxy' '--enable-linux-netfilter' '--with-systemd' '--with-openssl' '--enable-ssl-crtd' 'build_alias=x86_64-linux-gnu' 'CFLAGS=-g -O2 -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -ffile-prefix-map=/build/squid-CDRpf1/squid-6.6=. -flto=auto -ffat-lto-objects -fstack-protector-strong -fstack-clash-protection -Wformat -Werror=format-security -fcf-protection -fdebug-prefix-map=/build/squid-CDRpf1/squid-6.6=/usr/src/squid-6.6-1ubuntu5.1 -Wno-error=deprecated-declarations' 'LDFLAGS=-Wl,-Bsymbolic-functions -flto=auto -ffat-lto-objects -Wl,-z,relro -Wl,-z,now ' 'CPPFLAGS=-Wdate-time -D_FORTIFY_SOURCE=3' 'CXXFLAGS=-g -O2 -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -ffile-prefix-map=/build/squid-CDRpf1/squid-6.6=. -flto=auto -ffat-lto-objects -fstack-protector-strong -fstack-clash-protection -Wformat -Werror=format-security -fcf-protection -fdebug-prefix-map=/build/squid-CDRpf1/squid-6.6=/usr/src/squid-6.6-1ubuntu5.1 -Wno-error=deprecated-declarations'

2025年7月11日更新:
注意!!!:最近发现默认安装的squid已经到了6.10版本,该版本需要额外安装以下内容,否则无法正常启用https代理

apt install squid-openssl

3.配置(重点)

apt安装的squid,其配置内容路径:/etc/squid/squid.conf

cd /etc/squid
#备份配置文件
mv squid.conf squid.conf.bak
#调整配置内容
vi /etc/squid/squid.conf

填入增加以下配置

#将8888设为http代理端口 示例 注意默认端口为3128
http_port 8888
#将8887端口设为https代理端口
https_port 8887 tls-cert=/data/cert/www.xxx.com_bundle.crt tls-key=/data/cert/www.xxx.com.key

#acl(access control list) 将8887标记为安全ssl端口,必须配置!
acl SSL_ports port 8887

#允许所有访问
http_access allow all

#隐匿代理头(可选)
request_header_access X-Forwarded-For deny all
request_header_access From deny all
request_header_access Via deny all

关于配置项的简单说明:
http_port即为http代理的端口。
https_port即为https代理的端口。
http_port和https_port都可以代理http和https的请求,唯一的区别是htts_port是加密的,对于有些公司,你走http代理,是可以被监测到你访问的网站的地址进而禁止你访问淘宝,走https代理则不会。

https_port证书需要自己准备。
acl SSL_ports port必须配置!

4.重启squid

systemctl restart squid

5.测试

给自己的电脑配置个代理,访问一下即可,这里就不写了

参考:

https://www.squid-cache.org/Versions/v6/cfgman/http_port.html
https://dushansilva.medium.com/trying-out-squid-proxy-with-http-https-in-ubuntu-18-04-part-1-a317fa59d0f7
https://dushansilva.medium.com/trying-out-squid-proxy-with-http-https-in-ubuntu-part-2-13a702f8e2b

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值