在ubuntu上在安装Squid代理服务器

Squid 是一个代理和缓存服务器,它将请求转发到所需的目的地,同时保存请求的内容,当你再次请求相同内容时,他可以向你提供缓冲内容,从而提高访问速度。Squid代理服务器目前支持的协议有:http、SSL、DNS、FTP。

一:安装Squid

1、更新您的系统软件包

apt update && sudo apt upgrade -y

2、安装policy代理

apt-cache policy squid

3、启动代理,并设置

apt install -y squid
systemctl start squid
systemctl enable squid
systemctl status squid

二:配置Squid代理

1、备份Squid配置文件

cp /etc/squid/squid.conf  /etc/squid/squid.conf.bk

2、编辑squid.conf

vim /etc/squid/squid.conf

3、修改代理端口

在squid.conf中查找http_port 3128

默认端口为3128,你可以修改为任意你想使用的端口,假如你只是希望自己私密使用,你可以选一个别从比较难找到的端口。

4、放通防火墙设置

ufw allow 8080/tcp
ufw enable

如未开启防火墙此步可省略。

5、设置Squid缓存大小

cache_mem 256 MB

6、配置使用的DNS

dns_nameservers 8.8.8.8 8.8.4.4

7、设置ACL访问和http access

设置acl,在squid.conf里面查找下面,并配置或添加。

设置http access访问,想出去的就allow,不想让出去的就deny。

以上配置就基本上配置好了。接下来重启squid服务

systemctl restart squid

三:划重点

1、屏蔽 Squid 代理服务器上的传出流量,关闭via on

# via on
via off

2、去掉代理标头

request_header_access From deny all
request_header_access Server deny all
request_header_access WWW-Authenticate deny all
request_header_access Link deny all
request_header_access Cache-Control deny all
request_header_access Proxy-Connection deny all
request_header_access X-Cache deny all
request_header_access X-Cache-Lookup deny all 
request_header_access X-Forwarded-For deny all
request_header_access Pragma deny all
request_header_access Keep-Alive deny all

3、设置访问密码

设置一个名为test的用户访问密码

touch /etc/squid/passwd
chown proxy: /etc/squid/passwd
htpasswd /etc/squid/passwd test

编辑squid.conf,添加如下代码,以启用密码服务。

auth_param basic program /usr/lib/squid/basic_ncsa_auth /etc/squid/passwd
auth_param basic children 5
auth_param basic realm Squid Basic Authentication
auth_param basic credentialsttl 2 hours
acl auth_users proxy_auth REQUIRED
http_access allow auth_users

4、调试

显示配置文件中的错误

squid -k parse

显示auth的正确位置

dpkg -L squid | grep ncsa_auth

四:访问端设置

打开win11的设置,找到"网络和Internet",然后是"代理"

找到手动设置代理,如下图

在这里填上你刚才的Squid服务器IP和访问商品就配置好啦。

相关推荐
likfishdn几秒前
Linux的文件与目录管理
linux·运维·服务器
渲染101专业云渲染2 分钟前
川翔云电脑优势总结
服务器·3d·电脑·blender·maya
chian-ocean20 分钟前
Linux 文件缓冲区:高效数据访问的幕后推手
linux·运维·服务器
加油=^_^=22 分钟前
【Linux】进程优先级 | 进程调度(三)
linux·运维·服务器
橘子味的茶二31 分钟前
高级系统架构师--第十章:计算机网络
服务器·计算机网络·系统架构
吃汤圆的抹香鲸1 小时前
GoLand 安装包 绿色版 Win,Mac,Linux 包含IntelliJ全家桶 专为Go语言设计的集成开发环境(IDE)
linux·windows·macos·go·intellij-idea·go1.19
紫菜(Nori)1 小时前
短连接服务器压测-wrk
服务器·压力测试
追寻光1 小时前
Cannot find a valid baseurl for repo: base/7/x86_64
linux
元气满满的热码式1 小时前
Docker数据卷操作实战
linux·运维·docker·云原生·容器
陆沙1 小时前
deepseek-r1-centos-本地服务器配置方法
linux·服务器·centos