说明
云主机1作为反向代理服务器
- 云主机1: 47.104.104.133(公网IP)
- 云主机2: 172.31.55.77(内网IP)
配置云主机1 nginx 配置
http {
# 其他配置
proxy_cache_path /ngx_tmp levels=1:2 keys_zone=test_cache:100m inactive=1d max_size=10g;
upstream httpget {
server 172.31.55.77:80;
}
server {
# 其他配置
location / {
add_header Nginx-Cache "$upstream_cache_status";
proxy_cache test_cache;
proxy_cache_valid 24h;
proxy_pass http://httpget;
}
}
}
访问 云主机1 的 80 端口
可以看到已经返回云主机2的内容
查看 /ngx_tmp 目录,可以看到已经有缓存内容
删除 云主机2 的静态文件后
- 直接访问云主机2,已经无法获取html
- 访问云主机1,可以正常显示云主机2的内容,说明这里是从缓存里面获取的html