ubuntu18.04 配置squid代理服务器

1.安装环境
sudo apt install openssh-server
sudo apt install apache2-utils
sudo apt install squid


 

2.安全起见,设置服务器密码

sudo htpasswd -c /etc/squid/passwd 用户名
# 输入两次明文密码,会自动生成passwd文件,共代理服务鉴权验证使用

3.修改配置文件 
cd /etc/squid/
sudo cp squid.conf squid.conf.bak
sudo rm -rf /etc/squid/squid.conf
sudo vi /etc/squid/squid.conf

可以直接用下图配置

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
# 注意此处路径具体为/usr/lib64还是/usr/lib视具体情况而定
# 查找指令为    sudo find / -name basic_ncsa_auth  
auth_param basic program /usr/lib/squid/basic_ncsa_auth /etc/squid/passwd
acl auth_user proxy_auth REQUIRED
http_access allow auth_user

http_access deny !Safe_ports

http_access deny CONNECT !SSL_ports

http_access deny all

http_port 3128  

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 (Release|Packages(.gz)*)$      0       20%     2880
refresh_pattern .               0       20%     4320

request_header_access X-Forwarded-For deny all
request_header_access From deny all
request_header_access Via deny all

四.启动代理服务器

sudo squid -z  # 初始化缓存文件,选用项,有时出现问题很玄学
sudo service squid start
sudo service squid status 查看启动是否成功

如果提示服务已启动,可以重启服务

sudo service squid restart


    

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值