squid 反向代理

许多大型门户网站架构中都采用了反向代理加速,使用比较多的是nginx、squid等。通过squid反向代理加速网站的访问速度,可将不同的url(万维寻址)请求分发到后台不同的Web服务器上,同时互联网用户只能看到反向代理服务器的地址,加强了网站的访问安全。

 

试验环境:

web1:  192.168.100.111/24 (vmnet1)   gw:  192.168.100.222 Apache

web2: 192.168.100.66/24 (vmnet1)  gw:  192.168.100.222 Apache

squid:  eth0 192.168.100.222 (vmnet1)

      eth1 192.168.200.123 (vmnet3)

windows xp :192.168.200.66/24 gw:192.168.200.123

注:vmnet3 模拟外网

web1.web2机器都安装yum 安装apache。略

cd /etc/squid/

cp squid.conf squid.conf.$(date +%F)

vim squid.conf

http_port 80 vhost //指定监听端口,accel加速模式,vhost启用反向代理

cache_mem 64MB  //squid使用的其它内存上限,用于传输中的对象/热对象/非缓存对象

cache_dir ufs /var/spool/squid 4096 16 256    //定义squid的cache存放路径 、cache目录容量(单位M)、一级缓存目录数量、二级缓存目录数量

cache_effective_user squid  指定squid 用户

cache_effective_group squid  指定squid组

dns_nameservers 202.106.0.20 8.8.8.8  为了使squid 能解析域名需要定义真实DNS地址

cache_access_log /var/log/squid/access.log   //访问日志文件路径,记录了用户访问 Internet 的详细信息,可以查看每用户的上网记录    日志文件

cache_store_log /var/log/squid/store.log  //缓存日志文件路径,记录了缓存相关的日志信息

visible_hostname squid.amber.com  //本机名

cache_peer 192.168.100.111 parent 80 0 no-query originserver  round-robin name=apache1  节点服务器  round-robin 使用轮询

cache_peer 192.168.100.66 parent 80 0 no-query originserver  round-robin name=apache2

将www.amber.com域的请求通过RR轮询方式转发到两个节点中的一个

cache_peer_domain apache1  apache2 www.amber.com

 http_access allow all      //允许所有

cache_peer_access apache1 allow all

cache_peer_access apache2 allow all

/etc/init.d/httpd stop

ss -anpt |grep 80

/etc/init.d/squid restart

/etc/init.d/iptables stop

客户机测试

修改hosts文件  在c盘 windows/system32/drivers/etc/    hosts

主要出错问题在网络 ,或者不轮询。要调整好。

posted @ 2018-08-23 21:20  thomes  阅读(541)  评论(0)    收藏  举报