总体结构:

clientnginx_proxysquidnginx_web
192.168.2.1192.168.2.128192.168.2.133192.168.2.136
拓扑图如下
wKiom1kpjwCR35YOAAFNoJ7w7pg382.png-wh_50


192.168.2.128配置:

             yum install nginx -y

          vim /etc/nginx/conf.d/default.conf

server {

listen 80 default_server; //指定监听

server_name www.cdbtest.com;//域名访问

# Load configuration files for the default server block.

include /etc/nginx/default.d/*.conf;

location / {

proxy_pass http://192.168.2.133;//squid服务器IP

}

error_page 404 /404.html;

location = /40x.html {

}

error_page 500 502 503 504 /50x.html;

location = /50x.html {

}

}

192.168.2.133配置:

  yum install -y squid

           

vim /etc/squid/squid.conf

http_port 192.168.2.133:80 accel vhost

  //侦听本机80端口

cache_peer 192.168.2.136 parent 80 0 originserver   /

//指定回源IP,即源服务器

cache_log /var/log/squid/var/logs/cache.log

//指定日志文件

acl deny_img urlpath_regex -i ^/p_w_picpath

no_cache deny deny_img

//使用acl不缓存源服务器的/usr/share/nginx/html/p_w_picpath下的任何文件

refresh_pattern -i .*\.txt$      43200  100%    43200

对以.txt结尾的文件实行缓存一个月

192.168.2.136 配置 :      

 yum install nginx -y

vim /etc/nginx/conf.d/default.conf

server {

listen       80 default_server;//侦听本机80端口

listen       [::]:80 default_server;//IPV6

server_name   www.cdntest.com;//本机域名

root         /usr/share/nginx/html; //挂载目录

# Load configuration files for the default server block.

include /etc/nginx/default.d/*.conf;

location / {

}

error_page 404 /404.html;

location = /40x.html {

}

error_page 500 502 503 504 /50x.html;

location = /50x.html {

}

}

cd  /usr/share/nginx/html

mkdir p_w_picpath

//添加text文件和jpg,png等图片文件加入/usr/share/nginx/html/p_w_picpath用于测试

在192.168.2.1上测试一下

wKioL1km1sSzEAs6AAGK1e62rws976.png-wh_50

在192.168.2.128上curl命令测试jpg图片和text文件

wKiom1kpP6KjdobwAABmL52pP4c041.png-wh_50

在192.168.2.133上查看squid access.log

wKiom1kpPk2SvvNzAACYToTqBSk669.png-wh_50


在192.168.2.136上查看nginx access.log,没有关于txt的日子

wKiom1kpP2GTuZ8jAADSk1DOP4A246.png-wh_50