The proxy_cache_bypass of nginx is set, but the request is not origin-pull.

just contacted nginx, configured micro-cache on the server, set proxy_cache_bypass to $arg_nocache; and added nocache=true to the request connection, and then saw X-Cache-Status:BYPASS in the browser"s header, that is to say, the parameter setting should be in effect, but what happened when the request did not pull back to the origin? For the answer, paste the policy code of nginx cache

.
proxy_cache_path  /mnt/data/nginx/cache levels=1:2 keys_zone=nuxt-cache:25m max_size=10g inactive=60m use_temp_path=off;

location / {
        expires $expires;

        add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload" always;
        add_header X-Frame-Options "SAMEORIGIN";
        add_header X-Cache-Status $upstream_cache_status;

        proxy_redirect                      off;
        proxy_set_header Host               $host;
        proxy_set_header X-Real-IP          $remote_addr;
        proxy_set_header X-Forwarded-For    $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto  $scheme;
        proxy_ignore_headers        Cache-Control;
        proxy_http_version          1.1;
        proxy_read_timeout          1m;
        proxy_connect_timeout       1m;
        proxy_pass                  http://127.0.0.1:3000;
        proxy_cache                 nuxt-cache;
        proxy_cache_bypass          $arg_nocache; -sharp probably better to change this
        proxy_cache_valid           200 302 60m; -sharp set this to your needs
        proxy_cache_valid           any     10m;  -sharp set this to your needs
        proxy_cache_lock            on;
        proxy_cache_use_stale       updating;
        proxy_cache_key             $uri$is_args$args;
    }
Jul.05,2022

found the problem by myself. This configuration does not meet the routing request of the foreground. I forgot to use the server rendering of nuxt, which uses the environment variables shared by the client and the server. The rendering of the page is asyncData, and all the requests are called using axios. This parameter is not attached to the request. The url in the browser address bar is all front-end routing, while the requests of axios are all back-end interfaces. So the returned document is still cached. You need to configure the request interceptor of axios or match the routing parameters in nginx

Menu