1、控制瀏覽器緩存
server {
listem 80;
server_name www.tomcats.com;
location / {
proxy_pass http://tomcats;
expires 10s; #瀏覽器緩存10秒鐘
#expires @22h30m #在晚上10點30的時候過期
#expires -1h #緩存在一小時前時效
#expires epoch #不設置緩存
#expires off #緩存關閉,瀏覽器自己控制緩存
#expires max #最大過期時間
}
}
2、反向代理緩存
upstream tomcats {
server 192.168.1.173:8080 weight=1;
server 192.168.1.174:8080 weight=5;
server 192.168.1.175:8080 weight=2;
}
#proxy_cache_path 設置緩存保存的目錄的位置
#keys_zone設置共享內以及占用的空間大小
#mas_size 設置緩存最大空間
#inactive 緩存過期時間,錯過此時間自動清理
#use_temp_path 關閉零時目錄
proxy_cache_path /usr/local/nginx/upsteam_cache keys_zone=mycache:5m max_size=1g inactive=8h use_temp_path=off;
server {
listem 80;
server_name www.tomcats.com;
#開啟并使用緩存
proxy_cache mycache;
#針對200和304響應碼的緩存過期時間
proxy_cache_valid 200 304 8h;
location / {
proxy_pass http://tomcats;
}
}