总体结构:
client | nginx_proxy | squid | nginx_web |
192.168.2.1 | 192.168.2.128 | 192.168.2.133 | 192.168.2.136 |
![360反馈意见截图18720127106107119.png wKiom1kpjwCR35YOAAFNoJ7w7pg382.png-wh_50](https://s3.51cto.com/wyfs02/M01/97/28/wKiom1kpjwCR35YOAAFNoJ7w7pg382.png-wh_500x0-wm_3-wmp_4-s_4257257326.png)
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上测试一下
在192.168.2.128上curl命令测试jpg图片和text文件
在192.168.2.133上查看squid access.log
在192.168.2.136上查看nginx access.log,没有关于txt的日子
转载于:https://blog.51cto.com/12677403/1929540