我正在实现nginx作为Django项目的反向代理。现在我想实现下面的nginx的缓存配置:如果用户通过身份验证,绕过nginx缓存Django
proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=my_cache:5m max_size=1g inactive=60m;
proxy_temp_path /var/cache/nginx/tmp;
server {
...
location/{
proxy_pass http://127.0.0.1:8000;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Host $server_name;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
add_header P3P 'CP="ALL DSP COR PSAa PSDa OUR NOR ONL UNI COM NAV"';
# cache
proxy_cache my_cache;
proxy_cache_min_uses 1;
proxy_cache_valid 200 302 10m;
proxy_cache_valid 404 1m;
proxy_ignore_headers X-Accel-Expires Expires Cache-Control;
proxy_cache_use_stale error timeout invalid_header http_500 http_502 http_503 http_504;
proxy_cache_lock on;
proxy_hide_header "Set-Cookie";
add_header X-Proxy-Cache $upstream_cache_status;
}
}
所有的伟大工程,但我想它,以便验证的用户能够绕过缓存,否则当他们更新网站的内容,他们赢了不会看到更改,只有缓存的内容才会到期。
什么是最好的方法来解决这个问题?
任何帮助将不胜感激。
感谢
缓存动态内容几乎总是一个坏主意 – e4c5
网站并不是非常动态的,只是当管理员进行更新时,进行修改的用户将无法查看更新,直到缓存过期(或者他们在url栏中输入nocache)。 – tdsymonds
你每天获得多少页面浏览量 – e4c5