代理服务器的分类及适用环境: 代理服务器有传统代理、透明代理、反向代理三种类型 传统代理适用于任意网络环境,透明代理则只适用于内网,而反向代理则适用于外网访问内网的情况下 传统代理因为确切的知道代理服务器是谁,所以需要明确的指定代理服务器。
透明代理因为不知道代理服务器是谁,所以需要将请求发送给网关,由网关将请求发送给代理服务器 代理服务器的作用及好处: 提高Web访问速度、隐藏客户机的真实IP地址一、 传统代理: 传统代理拓扑图: 。
![Squid配置文档插图 Squid配置文档插图](https://www.tiejiang.org/wp-content/uploads/2013/11/20131111093739_67985.jpg)
声明: 本实验中客户机由真机代替进行测试。 1、挂载光盘、安装apache服务、生成网页文件并启动web服务:
![Squid配置文档插图1 Squid配置文档插图1](https://www.tiejiang.org/wp-content/uploads/2013/11/20131111093758_68636.png)
2、在客户机上通过浏览器访问:
![Squid配置文档插图2 Squid配置文档插图2](https://www.tiejiang.org/wp-content/uploads/2013/11/20131111093822_55617.png)
3、在web服务器上查看访问日志:
![Squid配置文档插图3 Squid配置文档插图3](https://www.tiejiang.org/wp-content/uploads/2013/11/20131111093845_76110.png)
由上图可见,本次访问是直接访问的web网站,而没有经过代理服务器。 4、挂载光盘,并安装squid代理服务器软件:
![Squid配置文档插图4 Squid配置文档插图4](https://www.tiejiang.org/wp-content/uploads/2013/11/20131111093917_28544.png)
5、优化squid配置文件,去掉不必要的注释行和空行:
![Squid配置文档插图5 Squid配置文档插图5](https://www.tiejiang.org/wp-content/uploads/2013/11/20131111093935_25971.png)
6、配置squid配置文件:
![Squid配置文档插图6 Squid配置文档插图6](https://www.tiejiang.org/wp-content/uploads/2013/11/20131111093956_97572.png)
7、启动squid代理服务:
![Squid配置文档插图7 Squid配置文档插图7](https://www.tiejiang.org/wp-content/uploads/2013/11/20131111094029_18294.png)
8、在客户机上设置代理:
![Squid配置文档插图8 Squid配置文档插图8](https://www.tiejiang.org/wp-content/uploads/2013/11/20131111094059_56441.png)
9、在客户机上通过浏览器访问web服务器:
![Squid配置文档插图9 Squid配置文档插图9](https://www.tiejiang.org/wp-content/uploads/2013/11/20131111094124_52717.png)
10、在web服务器上查看访问日志:
![Squid配置文档插图10 Squid配置文档插图10](https://www.tiejiang.org/wp-content/uploads/2013/11/20131111094147_18813.png)
由上图可见,本次访问是通过代理服务器进行的。 二、透明代理: 透明代理拓扑图:
![Squid配置文档插图11 Squid配置文档插图11](https://www.tiejiang.org/wp-content/uploads/2013/11/20131111094335_65590.jpg)
声明: 代理服务器有两块网卡,VM5连接内网客户机,VM3连接外网服务器。 客户机上的VM3网卡IP为192.168.200.1,用以测试访问WEB。 1、去掉客户机代理设置:
![Squid配置文档插图12 Squid配置文档插图12](https://www.tiejiang.org/wp-content/uploads/2013/11/20131111094356_76151.png)
2、在客户机上通过浏览器访问web服务器:
![Squid配置文档插图13 Squid配置文档插图13](https://www.tiejiang.org/wp-content/uploads/2013/11/20131111094422_36130.png)
3、在web服务器上查看访问日志:
![Squid配置文档插图14 Squid配置文档插图14](https://www.tiejiang.org/wp-content/uploads/2013/11/20131111094446_33381.png)
由上图可见,本次访问是没有经过代理服务器的。 4、配置代理服务器:
![Squid配置文档插图15 Squid配置文档插图15](https://www.tiejiang.org/wp-content/uploads/2013/11/20131111094517_74967.png)
5、重启代理服务:
![Squid配置文档插图16 Squid配置文档插图16](https://www.tiejiang.org/wp-content/uploads/2013/11/20131111094619_59048.png)
6、配置防火墙规则:
![Squid配置文档插图17 Squid配置文档插图17](https://www.tiejiang.org/wp-content/uploads/2013/11/20131111094646_37350.png)
7、重新设置客户机的代理:
![Squid配置文档插图18 Squid配置文档插图18](https://www.tiejiang.org/wp-content/uploads/2013/11/20131111094723_99876.png)
8、在客户机尝试通过浏览器访问WEB服务器:
![Squid配置文档插图19 Squid配置文档插图19](https://www.tiejiang.org/wp-content/uploads/2013/11/20131111094746_81842.png)
9、在web服务器上查看访问日志:
![Squid配置文档插图20 Squid配置文档插图20](https://www.tiejiang.org/wp-content/uploads/2013/11/20131111094814_51344.png)
由上图可见,本次访问是经过代理服务器而进行的。 10、配置代理服务器ACL规则:
![Squid配置文档插图21 Squid配置文档插图21](https://www.tiejiang.org/wp-content/uploads/2013/11/20131111094844_72009.png)
11、在客户机上访问web服务器:
![Squid配置文档插图22 Squid配置文档插图22](https://www.tiejiang.org/wp-content/uploads/2013/11/20131111094922_82691.png)
12、设置代理服务器规则,允许访问10M以内的网页文件,超过10M就拒绝访问:
![Squid配置文档插图23 Squid配置文档插图23](https://www.tiejiang.org/wp-content/uploads/2013/11/20131111095030_40294.png)
13、在web服务器上生成一个大小为500M的视频文件和一个大小为3M的mp3文件:
![Squid配置文档插图24 Squid配置文档插图24](https://www.tiejiang.org/wp-content/uploads/2013/11/20131111095051_21917.png)
14、在客户机上访问MP3文件:
![Squid配置文档插图25 Squid配置文档插图25](https://www.tiejiang.org/wp-content/uploads/2013/11/20131111095113_29863.png)
如上图所示,可以正常访问,因为其大小没有超过10M。 继续访问视频文件test.rmvb:
![Squid配置文档插图26 Squid配置文档插图26](https://www.tiejiang.org/wp-content/uploads/2013/11/20131111095137_28358.png)
三、添加用户、密码认证: 添加用户、密码认证,在访问网页时必须输入特定的用户名和密码来访问。 1、配置squid配置文件,启用ncsa_auth(squid默认自带认证机制):
![Squid配置文档插图27 Squid配置文档插图27](https://www.tiejiang.org/wp-content/uploads/2013/11/20131111095203_70570.png)
2、在WEB服务器上创建认证文件并将其传送到代理服务器的/etc/squid/passwd:
![Squid配置文档插图28 Squid配置文档插图28](https://www.tiejiang.org/wp-content/uploads/2013/11/20131111095217_42269.png)
3、在客户机访问web服务器:
![Squid配置文档插图29 Squid配置文档插图29](https://www.tiejiang.org/wp-content/uploads/2013/11/20131111095241_10510.png)
访问成功:
![Squid配置文档插图30 Squid配置文档插图30](https://www.tiejiang.org/wp-content/uploads/2013/11/20131111095303_58202.png)
四、反向代理: 反向代理拓扑图:
![Squid配置文档插图31 Squid配置文档插图31](https://www.tiejiang.org/wp-content/uploads/2013/11/20131111095326_35296.jpg)
声明: 客户机为外网客户机,服务器为内网服务器,且web服务器上有两个基于不同IP的网站。 1、为web服务器生成一个子接口,并为其配置IP地址等信息:
![Squid配置文档插图32 Squid配置文档插图32](https://www.tiejiang.org/wp-content/uploads/2013/11/20131111095400_43912.png)
2、重启网卡服务:
![Squid配置文档插图33 Squid配置文档插图33](https://www.tiejiang.org/wp-content/uploads/2013/11/20131111095416_46101.png)
3、在代理服务器上测试网络连通性:
![Squid配置文档插图34 Squid配置文档插图34](https://www.tiejiang.org/wp-content/uploads/2013/11/20131111095435_75173.png)
4、在web服务器上创建两个网页存放目录,并分别生成网页文件:
![Squid配置文档插图35 Squid配置文档插图35](https://www.tiejiang.org/wp-content/uploads/2013/11/20131111095455_57639.png)
5、部署web服务器虚拟主机并重启web服务:
![Squid配置文档插图36 Squid配置文档插图36](https://www.tiejiang.org/wp-content/uploads/2013/11/20131111095516_71452.png)
6、关掉客户机的代理:
![Squid配置文档插图37 Squid配置文档插图37](https://www.tiejiang.org/wp-content/uploads/2013/11/20131111095537_96239.png)
7、在客户机通过192.168.200.253访问web服务器:
![Squid配置文档插图38 Squid配置文档插图38](https://www.tiejiang.org/wp-content/uploads/2013/11/20131111095616_42110.png)
8、在客户机通过192.168.200.252访问web服务器:
![Squid配置文档插图39 Squid配置文档插图39](https://www.tiejiang.org/wp-content/uploads/2013/11/20131111095637_23307.png)
9、配置代理服务器并重新加载配置文件:
![Squid配置文档插图40 Squid配置文档插图40](https://www.tiejiang.org/wp-content/uploads/2013/11/20131111095659_28465.png)
10、设置客户机的代理:
![Squid配置文档插图41 Squid配置文档插图41](https://www.tiejiang.org/wp-content/uploads/2013/11/20131111095721_26608.png)
11、在客户机上访问代理服务器:
![Squid配置文档插图42 Squid配置文档插图42](https://www.tiejiang.org/wp-content/uploads/2013/11/20131111095743_44398.png)