[root@LNMP squid]# ls /var/spool/squid/
00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F swap.state
[root@LNMP squid]# netstat -lnp #squid 端口是 3128
tcp 0 0 :::3128 :::* LISTEN 2488/(squid)
http_port 3128 这个代理端口是可以更改的。
--------------------------------------------------
在客户机进行测试设置代理,然后打开网页。网站是可以访问的,但是此时我们不能证实是通过代理来进行上网的。只能在linux 主机上进行抓包测试。
10.72.4.50 port :3128
[root@LNMP ~]# tcpdump -nn port 3128 #如果没有这个命令,yum install -y tcpdump
下图证明代理已经生效 。
进入到缓存目录可以查看到访问产生的临进文件
-------------------------------------------------------
访问控制设置(白明单):此时的代理网站可以访问任意的网站,那么就要做一些设置来限制某些网站。
[root@LNMP ~]# vim /etc/squid/squid.conf
acl http proto HTTP
acl good_domain dstdomain .linux.com .baidu.com #允许访问的 。dstdomain指定目标domain
http_access allow good_domain
http_access deny !good_domain # “!”非“good_domain”
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
楼主粗心的过错(小插曲)
[root@LNMP ~]# squid -kcheck #检查配置文件有没有错
2016/12/08 14:21:14| redreshAddToList: Unknown option '\.(jpg?www.myhack58.com|gif|png|js|css|mp3|mp4)': ignore_reload
# 排错 “ignore_reload”应该 为 “ignore-reload”
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[root@LNMP ~]# squid -kcheck #再次检查没有输出,即没有错误
[root@LNMP ~]# squid -kreconfig #重新应用配置文件
在windows客户端上测试
在别一台linux 客户机上行curl 测试
~~~~~~~~~~~~~~~~~~~~~~~~~~~
访问控制设置(黑明单)
acl bad_domain dstdomain .linux.com .baidu.com #不允许访问的
http_access deny bad_domain
http_access allow !bad_domain #非bad_domain
亲测,是被拒绝的。
--------------------------------------------------------------
反向代理的设置:
[root@LNMP ~]# vim /etc/squid/squid.conf #因为作为用户来看访问的是服务器,不知道是代理。
http_port 3128 #更改为 http_port 80 accel vhost vport
cache_peer 180.97.33.108 parent 80 0 originserver name=baidu
cache_peer_domain baidu www.baidu.com
#以www.baidu.com,为例,先ping 出百度的IP 180.97.33.108,指定代理名:oribinserver name=baidu。如果还要代理别的网站,就再写两行,每两行作为一个单元。且一定要知道网站的源IP.
[root@LNMP ~]# squid -kcheck
[root@LNMP ~]# squid -kreconfig
[root@LNMP ~]# netstat -lnp #端口被nginx 占用
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 1206/nginx
[root@LNMP ~]# /etc/init.d/nginx stop #停掉nginx ,
[root@LNMP ~]# /etc/init.d/squid stop
Stopping squid: ................ [ OK ]

◆◆0
发表评论