小编uky*_*ang的帖子

如何通过后端的 ETag/Last-Modified 字段更新 Nginx 反向代理缓存?

我正在尝试让我的 Nginx 反向代理正常工作。但是,我发现一旦文件被缓存,即使后端文件发生更改,它也永远不会更新/重新验证,这可以通过ETagorLAST-Modified字段来识别。有人可以帮我解决这个问题吗?

这是我的设置:

proxy: proxy.test.com
backend: back.example.com
Run Code Online (Sandbox Code Playgroud)

nginx 设置:

proxy_cache_path /home/cache levels=1:2 keys_zone=cache_rev:16m inactive=14d max_size=12g;
proxy_cache_key "$scheme://$host$request_uri";
server {
    listen 80 default_server;

    resolver 74.82.42.42;
    server_name proxy.test.com;

    location ~ ^/ {
        proxy_pass http://back.example.com$request_uri;
        proxy_redirect off;
        proxy_buffering on;
        proxy_cache_revalidate on;
        proxy_pass_header Set-Cookie;

        proxy_cache cache_rev;
        proxy_cache_use_stale  error timeout invalid_header updating http_500 http_502 http_503 http_504;
        proxy_cache_valid 200  1d;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

        add_header X-Cache-Status $upstream_cache_status;
    }
}
Run Code Online (Sandbox Code Playgroud)

这是更改的curl信息beforeafter后端文件。

更改前index.html

$ curl …
Run Code Online (Sandbox Code Playgroud)

nginx reverse-proxy

3
推荐指数
1
解决办法
9228
查看次数

标签 统计

nginx ×1

reverse-proxy ×1