0

I have a NGINX reverse proxy that sits in front of a node.js server (express). With a pretty basic configuration. The problem I'm running into is with NGINX's proxy caching feature. Here's the setup.

http {
  proxy_cache_path /tmp/nginx/zone1 levels=1:2
                     keys_zone=zone1:10m max_size=10g
                     inactive=10m use_temp_path off;
  ...
  server {

    ...
    location /assets/ {
      proxy_pass $frontend$request_uri;
      proxy_cache_key "$scheme$request_method$host$request_uri";
      proxy_cache zone1;
      proxy_cache_valid 200 302 10m;
      proxy_cache_lock on;
      add_header X-Proxy-Cache $upstream_cache_status;
      access_log off;
    }
    ...
  }
  ...
}

Our URI for assets looks like this /assets/1.0.0/(.css|.js|.png|etc..). We update the version in the URI during build time so it does change frequently, which I'm assuming should invalidate the proxy_cache_key and NGINX should go back upstream to get the new assets. But this never happens. I'm just left with my un-styled html page.

Once I clear the cached files manually and issue a nginx -s reload all is fine again. Am I missing something? Many thanks!

8
  • Where you define $scheme variable? May 21, 2017 at 3:09
  • @AlexanderT $scheme is a built in variable.
    – Snarf
    May 21, 2017 at 3:32
  • May be there is cached pages with old assets url? And nginx still receiving requests with old URI? May 21, 2017 at 3:40
  • @AlexanderT I thought that may have been the case too, but. I don't cache html so when the user receives the new document it makes a request to the new assets URL.
    – Snarf
    May 21, 2017 at 3:45
  • How exactly does the asset URL change between versions? May 22, 2017 at 12:02

0

You must log in to answer this question.

Browse other questions tagged .