代理web服务器

#################################################

*代理web服务器

假如web服务器在北京,那么国内的其他地方主机访问这个web服务,速度会变慢,所以需要在一个地区设立一个代理web服务器,从而加速网站访问的速度。

---squid代理web服务器

反向代理 ---> 加速访问速度
正向代理 ---> ×××

准备3台虚拟机分别为:Client(eth0 192.168.4.100)
             proxy (eth0 192.168.4.5 / eth1 192.168.2.5)
             Web1 (eth1 192.168.2.100)
【proxy】

下载squid软件包
yum -y install squid

修改配置文件
/etc/squid/squid.conf

http_access allow all
http_listen_port 80 vhost
visible_hostname www.sina.com
cache_peer 192.168.2.100 parent 80 0 originserver
cache_dir ufs /var/spool/squid 100 16 256

起服务
systemctl restart squid
systemctl enable squid

【Web1】

搭建web服务器

下载httpd软件包

yum -y install httpd

echo "192.168.2.100" > /var/www/html/index.html

【Client】

验证

curl (-i) http://192.168.4.5
192.168.2.100

实时跟踪新增日志消息
【Web1】

tailf /var/log/httpd/access_log

【proxy】

tailf /var/log/squid/access_log
tailf /var/spool/squid/00/00

##############################################

---varnish代理服务器

【proxy】

下载varnish软件包(由于yum仓库中没有此包,需要使用源码包编译)
事先准备好了脚本
tar -xf lnmp_soft..
cd lnmp_soft
./install_lnmp.sh

...

修改配置文件
/etc/sysconfig/varnish    //前端配置文件

VARNISH_LISTEN_PORT=80
VARNISH_STORAGE_SIZE=64M
VARNISH_STORAGE="malloc,${VARNISH_STORAGE_SIZE}"

/etc/varnish/default.vcl

 backend default {
    .host = "192.168.2.200";
        .port = "80";
    }

起服务
systemctl stop squid 80
systemctl stop httpd 80  //一个端口在同一时刻仅可以被一个程序所占有

源码包起服务 不能使用 systemctl restart varnish
要使用
/etc/init.d/varnish start

【Client】

验证
curl 192.168.4.5
192.168.2.100

查看日至
varnishlog    //查看系统的日至
varnishncsa     //查看访问日至
###############################################

*当web服务器修改页面后,因为代理服务器有缓存,导致用户访问的仍然是修改前的页面
如何解决: 
1.等(大约2分钟左右就会和web服务器一致)
2.实时更新
【Web1】
echo "aa" > /var/www/html/a.html
【Client】
curl 192.168.4.5/a.html
aa
【Web1】
echo "xx" > /var/www/html/a.html
【Client】
curl 192.168.4.5/a.html
aa

【proxy】

varnishadm -S /etc/varnish/secret -T 127.0.0.1:6082
>ban.url a.html

【Client】
curl 192.168.4.5/a.html
xx      

转载于:https://blog.51cto.com/13402236/2047688

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值