在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和访问商品就配置好啦。

相关推荐
梦想很大很大5 小时前
拒绝“盲猜式”调优:在 Go Gin 项目中落地 OpenTelemetry 链路追踪
运维·后端·go
Sinclair6 小时前
内网服务器离线安装 Nginx+PHP+MySQL 的方法
运维
叶落阁主6 小时前
Tailscale 完全指南:从入门到私有 DERP 部署
运维·安全·远程工作
0xDevNull13 小时前
Linux切换JDK版本详细教程
linux
进击的丸子13 小时前
虹软人脸服务器版SDK(Linux/ARM Pro)多线程调用及性能优化
linux·数据库·后端
茶杯梦轩14 小时前
从零起步学习RabbitMQ || 第二章:RabbitMQ 深入理解概念 Producer、Consumer、Exchange、Queue 与企业实战案例
服务器·后端·消息队列
甲鱼9291 天前
MySQL 实战手记:日志管理与主从复制搭建全指南
运维
Johny_Zhao2 天前
OpenClaw安装部署教程
linux·人工智能·ai·云计算·系统运维·openclaw
YuMiao3 天前
gstatic连接问题导致Google Gemini / Studio页面乱码或图标缺失问题
服务器·网络协议
chlk1233 天前
Linux文件权限完全图解:读懂 ls -l 和 chmod 755 背后的秘密
linux·操作系统