rss· 投稿· 设为首页· 加入收藏· 繁體版

配置Squid

1、检查安装状态
[root@rhel5 ~]# rpm -qa|grep squid
squid-2.6.STABLE6-3.el5
[root@rhel5 ~]#
2、修改/etc/squid/squid.conf文件
http_port 172.24.58.121:8888
172.24.58.121为代理服务器IP地址(下同)
8888为代理监听端口(下同)
3、启动Squid
[root@rhel5 ~]# service squid start
init_cache_dir /var/spool/squid... Starting squid: ..      [  OK  ]
[root@rhel5 ~]#
4、测试
在客户端的浏览器上设置代理:
http_proxy=http://172.24.58.121:8888
ftp_proxy=http://172.24.58.121:8888
打开浏览器,输入URL,会发现错误信息,代理服务器拒绝了服务
5、修改/etc/squid/squid.conf文件,添加访问控制信息:
在http_access deny all前添加如下语句,以允许172.24.58.0/24段的访问
http_access allow localhost
acl allow_client src 172.24.58.0/24
http_access allow allow_client
http_access deny all
6、重启Squid
[root@rhel5 squid]# service squid restart
Stopping squid:                                            [  OK  ]
Starting squid: .                                          [  OK  ]
[root@rhel5 squid]#
7、测试
打开浏览器,输入URL,访问成功
以上是简单的配置,对于访问控制还有一下一些常用控制方法:
1、通过源IP控制
acl whitelist src 172.24.58.123 172.24.58.124 172.24.58.125
http_access allow whitelist
http_access allow! whitelist
这个设置只允许在whitelist组里面的IP,拒绝其他所有IP
acl myclients src 172.24.58.0/24
acl all src 0.0.0.0/0.0.0.0
acl myfriends src "/etc/squid/myfriends"
http_access allow myfriends
http_access allow myclients
http_access deny all
这个设置允许myclients组(172.24.58.0/24段)和myfriends组里面的IP,拒绝其他所有,myfriends组的IP在/etc/squid/myfriends文件里面添加,如:
172.24.58.123
172.24.58.124
172.24.58.125
2、限制使用代理服务器的域
acl myclients src test.com.cn test.net.cn
acl all src 0.0.0.0/0.0.0.0
http_access all myclients
http_access deny all
这个设置允许test.com.cn和test.net.cn域的用户访问,拒绝其他
3、限制访问站点
acl blacklist_ip dst "/etc/squid/acl/blacklist_ip"
acl blacklist_domain dst "/etc/squid/acl/blacklist_domain"
http_access deny blacklist_ip
http_access deny blacklist_domain
这个设置禁止列在/etc/squid/acl/blacklist_ip和/etc/squid/acl/blacklist_domain文件中的IP和域名
3、正则表达式的使用
acl banned_site_list1 url_regex ^http://www.test.com
acl banned_site_list2 url_regex -i 3721
http_access deny banned_site_list1
http_access deny banned_site_list2
4、对个别用户进行定制
acl special_user src 172.24.58.123
acl special_url rul_regex ^http://192.168.1.10
http_access allow special_user special_rul
http_access deny special_url
这个配置允许172.24.58.123访问192.168.1.10,其他的均拒绝访问以http://192.168.1.10开始的URL
5、上网时间控制
格式:
acl name time [day-list] [start_hour:minute-end_hour:minute]
例:
acl admin src 172.24.58.123
acl allowed_clients src 192.168.8.0/255.255.255.0
acl all src 0.0.0.0/0.0.0.0
acl maintain_time time S 0:00-2:00
acl worktime time MTWHF 8:30-17:00
http_access deny !admin maintain_time
http_access allow admin maintain_time
http_access allow allowed_clients worktime
http_access deny !allowed_clients
这个设置拒绝非管理员用户在维护时段访问代理服务器,允许用户在工作时段内访问,其他时间禁止访问
6、限制代理类型
Squid通过限制目的端口和协议来实现代理类型控制
acl safe_ports port 80 21 443 1025-65535
acl ftp proto FTP
acl mynet src 172.24.58.0/24
acl all src 0.0.0.0/0.0.0.0
http_access allow mynet
http_access deny !safe_ports
http_access deny ftp
http_access deny all
7、透明代理
查看设置状态:
[root@rhel5 ~]# cat /proc/sys/net/ipv4/ip_forward
0
[root@rhel5 ~]#
显示结果为0,需要激活此功能
[root@rhel5 ~]# echo "1" > /proc/sys/net/ipv4/ip_forward
[root@rhel5 ~]# cat /proc/sys/net/ipv4/ip_forward      
1
[root@rhel5 ~]#
修改/etc/squid/squid.conf文件
httpd_accel_host virtual
httpd_accel_port 80
httpd_accel_with_proxy on
httpd_accel_uses_host_header on
http_access allow all
重启squid服务
[root@rhel5 squid]# service squid restart
Stopping squid:                                            [  OK  ]
Starting squid: .                                          [  OK  ]
[root@rhel5 squid]#
顶一下
(0)
踩一下
(0)