Squid 正向代理配置

Squid 正向代理配置

1、删除主配置文件重写写入配置

rm -f /etc/squid/squid.conf

2、重新写入配置正向代理

vim /etc/squid/squid.conf
# 监听端口
http_port 3128
# acl权限控制
acl manager proto cache_object
acl localhost src 127.0.0.1/32 ::1
acl to_localhost dst 127.0.0.0/8 0.0.0.0/32 ::1
acl localnet src 10.0.0.0/8     # RFC1918 possible internal network
acl localnet src 172.16.0.0/12  # RFC1918 possible internal network
acl localnet src 192.168.0.0/16 # RFC1918 possible internal network
acl SSL_ports port 443
acl Safe_ports port 80 8080         # http
acl Safe_ports port 21          # ftp
acl Safe_ports port 443         # https
acl CONNECT method CONNECT
http_access allow manager localhost
http_access deny manager
http_access deny !Safe_ports
http_access deny CONNECT !SSL_ports
http_access allow localnet
http_access allow localhost
http_access allow all
# 缓存文件格式 aufs 缓存路径 目录1024大小MB 16子目录 256子子目录   
cache_dir aufs /data/cache 1024 16 256
# 内存占用大小
cache_mem 128 MB
hierarchy_stoplist cgi-bin ?
coredump_dir /var/spool/squid
# 以某个字符开头的进行缓存缓存10080秒
refresh_pattern ^ftp:           1440    20%     10080
refresh_pattern ^gopher:        1440    0%      1440
refresh_pattern -i (/cgi-bin/|\?) 0     0%      0
# 以某个字符结尾的进行缓存 缓存2880秒
refresh_pattern \.(jpg|png|gif|mp3|xml) 1440    50%     2880    ignore-reload
refresh_pattern .               0       20%     4320
主配置文件

3、查看语法是否有错

squid -kcheck
报错:squid: ERROR: No running copy
注:这是说squid还未启动,没有关系,显示成这样说明配置文件没有问题了
报错

4、添加目录权限

# 创建缓存目录
mkdir /data/cache
# 该目录赋予squid用户所属权限
chown -R squid:squid /data/cache/
# 初始化目录
squid -z

5、重启服务

/etc/init.d/squid stop
/etc/init.d/squid start

6、查看启动情况

ps aux |grep squid

root      7201  0.0  0.7  14524  2444 ?        Ss   16:25   0:00 squid -f /etc/squid/squid.conf
squid     7204  0.0  2.7  17468  9024 ?        S    16:25   0:00 (squid) -f /etc/squid/squid.conf
squid     7205  0.0  0.2   3280   916 ?        S    16:25   0:00 (unlinkd)
查看启动进程

测试正向代理

windos测试

1、使用IE 添加代理

IE-->Internet选项-->链接-->局域网设置-->代理服务器高级-->IP端口

2、服务端抓包测试

tcpdump -nn port 3128

Linux测试

curl -xlocalhost:3128 网站域名 -I
第一次访问:MISS
第二次访问:HIT 锁定
显示缓存:Via: 1.0 localhost.localdomain (squid/3.1.10)

 

posted @ 2018-02-03 13:24  kevin.Xiang  阅读(1346)  评论(0编辑  收藏  举报