squid配置的几个例子



以下是配置的几个例子

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、透明代理
查看设置状态:
# cat /proc/sys/net/ipv4/ip_forward
0
#
显示结果为0,需要激活此功能
# echo '1' > /proc/sys/net/ipv4/ip_forward
# cat /proc/sys/net/ipv4/ip_forward
1
#
修改/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的配置文件路径在/etc/squid/squid.conf

Squid网络地址配置选项

http_port

该选项指定squid监听HTTP请求只用的端口默认是3128如果需要使用代理功能需要与IP地址一起使用如:http_port 192.168.8.11:80

icp_port

该选项指定了squid同其他相邻的缓存服务器之间发送和接收到ICP请求侦听的端口设置0为禁止该功能默认为3130

htcp_port

该选项指定了squid同其他相邻的缓存服务器之间发送和接收到HTCP请求侦听的端口设置0为禁止该功能默认为4827

mcast_groups

该选项指定了一个多播组,通过它squid服务可以接收多播形式的ICP查询,该选项只在想接收时设定默认为none默认为不支持

如:mcast_groups 239.128.16.128 224.0.1.20

tcp_outgoing_address

该选项用于连接远程服务器也可用于HTCP和CARP方式和其他缓存服务器通信

默认形式:tcp_outgoing_address 255.255.255.255

udp_incoming_address

该选项用于squid服务器接收其他缓存服务器的ICP数据

如:udp_incoming_address 192.168.1.1

udp_outgoing_address

该选项用于squid服务器发送ICP数据报到其他缓存服务器

如:udp_outgoing_address 192.168.1.1

Squid缓存配置

ceche_mem

指定缓存占用多大内存默认为8MB

如:cache_mem 128MB

cache_swap_low(percent,0-100)

指定缓存对象交换的最低限度百分比默认为90%

如:cache_swap_low 90

cache_swap_high(percent,0-100)

执行缓存对象交换的最高限度百分比默认为95%

如:cache_swap_high 95

maximum_object_size(bytes)

大于该选项执行的对象将不被保存在硬盘上默认为4MB

如:maximum_object_size 4MB

minimum_object_size(bytes)

规定制定大小的对象将不在缓存到硬盘,默认是全部缓存

如:minimum_object_size 3MB

maximum_object_size_ni_memory(bytes)

规定大于指定大小的对象将不再缓存到内存,默认为8KB

如:maximum_object_size_ni_memory 8KB

Squid日志和缓存目录配置

cache_dir

指定系统使用的存储类型

默认:cache_dir ufs /var/spool/squid 100 16 256

cache_access_log

该选项用来制定cache存取日志的文件路径

默认:cache_access_log/var/log/squid/access.log

cache_log

该选项用来设定缓存日志文件的存储路径

默认:cache_log /var/log/squid/cache.log

emulate_httpd_log

设置是都启动缓存类似于httpd守护进程的日志功能默认为关闭

如需设置如:emulate_httpd_log on (off为关闭)

mime_table

该选项用来指定存储squid支持的MIME类型的文件

默认:mime_table /etc/squid/mime.conf

pid_filename

该选项指定squid写入自己进程ID的文件

默认:pid_filename /var/run/squid.pid

Squid超时设置

connect_timeout

向外连接的超时设置,默认为120秒

如:connect_timeout 120 seconds

peer_connect_timeout

等待对方TCP连接超时的时间限制

如:peer_connect_timeout 2 minutes

client_lifetime

客户端同代理服务器连接的生命期默认为1天

默认:client_lifetime 24 hours


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值