squid搭建代理服务器

安装squid

yum install -y squid


安装httpd(用于后面生成密码文件)
 
yum install -y httpd  或者 yum install httpd-tools -y
 

配置文件 /etc/squid/squid.conf
 
vim /etc/squid/squid.conf

修改/添加以下信息

1
2
3
4
5
6
7
8
9
10
11
12
http_port 3128
#  监听端口号,可以按需修改
#  http_port 0.0.0.0:3128   #这样写会同时监听ipv6和ipv4的端口
 
#以下内容一般加在文末
cache_mem 128 MB     #内存中的缓存大小
maximum_object_size 16 MB    #最大被缓存文件大小,这个配合下面的cache_dir使用,只作用于缓存到磁盘的文件。
cache_dir ufs /var/spool/squid 100 16 256
#缓存文件夹,默认是只在内存中进行缓存的。这里指定缓存大小为100M,第一层子目录为16个,第二层为256。   
access_log /var/log/squid/access.log     #定义访问日志路径
visible_hostname www.test.com     #随意填写一个域名
cache_mgr airoot@qq.com        #随意写一个邮箱

  1、如果不需要带用户认证,只需启用这条即可(安全性很差)

            http_access allow all

  2、带用户认证配置(这里通过ncsa认证模块来为我们的squid添加认证)

1
2
3
htpasswd -c /etc/squid/passwd airoot       #创建一个密码文件名为passwd,账号名为airoot的密码文件
# 回车之后提示输入密码,在此这里我设置的密码为 321654
# 注意密码不要超过8位 

  2.1 验证密码文件

1
2
3
4
5
6
/usr/lib64/squid/basic_ncsa_auth /etc/squid/passwd
# 输入 用户名 密码
airoot 321654
# 提示OK说明成功,ERR是有问题,请检查一下之前步骤
OK
# 测试完成,crtl + c 打断

  2.2 配置文件 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#注释以下内容:
# http_access deny !Safe_ports
# http_access deny CONNECT !SSL_ports
# http_access deny to_localhost
# http_access allow localnet
# http_access deny all
 
#在代码后添加验证和安全相关命令
acl OverConnLimit maxconn 16       #定义每个IP最大允许16个连接,防止攻击
 
auth_param basic program /usr/lib64/squid/basic_ncsa_auth /etc/squid/passwd      #选择的认证方式为basic,定义认证程序路径和密码文件路径。
auth_param basic children 5         #认证程序的进程数
auth_param basic realm airoot's Squid Server        #客户端在使用代理时,输入密码时弹出来的提示框中的描述文字
auth_param basic credentialsttl 5 hours     #认证有效时间
acl auth_user proxy_auth REQUIRED     #定义认证的用户
http_access deny OverConnLimit       #超出之前设定的连接数则拒绝
http_access allow auth_user     #允许认证的用户访问
http_access deny all     #拒绝所有其它访问
 
 
#题外话
# acl auth_user proxy_auth REQUIRED 等于 acl authenticated proxy_auth REQUIRED
# http_access allow auth_user 等于 http_access allow authenticated

初始化Squid

1
squid -z

启动命令与开机自启

1
2
3
4
5
6
7
8
9
# 启动
systemctl start squid.service
# 停止
systemctl stop squid.service
# 重启
systemctl restart squid.service
 
#设置开机自启
systemctl enable squid.service

 

 

 

iptables -t nat -I PREROUTING -i eth0 -s 192.168.10.0/24 -p tcp --dport 80 -j REDIRECT --to 3128  # 设置重定向,把通过网关服务器的80端口请求重定向为3128端口请求,因为squid没有80端口,不重定向的话数据包会被丢弃



参考地址 https://tms.isuanyun.com/#/blog/58

win10设置代理访问

设置》》》》》》》》》》》网络和internet》》》》》》》》》》》》》》》》代理》》》》》》》》》》》》填写ip和端口



posted @ 2021-03-11 22:50  woaibaobei  阅读(612)  评论(0编辑  收藏  举报