- 同一個URL,訪問之後出現了不同的頁面,這是因爲我們在後臺配置了代理,但是,沒有開啓緩存,所以導致了下面這種情況。
- 代理服務器配置部分:
upstream muyang {
server 192.168.127.130:80;
server 192.168.127.130:81;
server 192.168.127.130:82;
}
proxy_cache_path /opt/cache levels=1:2 keys_zone=muyang_cache:10m max_size=1g inactive=60m use_temp_path=off;
server {
listen 86;
server_name localhost;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
location / {
proxy_cache off;//這兒關閉了緩存,導致了輪詢頁面。若想開啓,可以設置爲muyang_cache.
#proxy_cache muyang_cache;
proxy_pass http://muyang;//你的代理url,你上面配置的upstream名稱
proxy_cache_valid 200 304 12h;//對於返回狀態爲200,304的,緩存12h
proxy_cache_valid any 6m;//其他的,都是6m
proxy_cache_key $host$uri$is_args$args;//key值參數
proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;//若正在訪問的某臺出現了所列的故障,詢問下一臺。
add_header Nginx_Cache "$upstream_cache_status";//添加緩存狀態信息於頭部
#proxy_pass http://127.0.0.1:81;
include proxy_params;
}