2

I'm using Nginx to serve static files (while also used as a revers proxy for my NodeJS express RestAPI). The problem is when I push a new git commit to the server, users will still get the old (last revision) files. The workaround for now is that the user clear his cache in browser.

What could be the reason for this? I guess this is some server side caching misconfiguration? See below my nginx config (basic + include).

As you can see below, static files (.html, .js, .css) resides under /var/www/frontend

##
# Basic Settings
##

sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
# server_tokens off;

# server_names_hash_bucket_size 64;
# server_name_in_redirect off;

include /etc/nginx/mime.types;
default_type application/octet-stream;

listen 80;

server_name **REMOVED_FOR_PRIVACY_REASONS**;

proxy_cache_valid 404 1m;

location / {
        root /var/www/frontend;
        index index.html
        try_files try_files $uri $uri/ =404;

        #proxy_cache backcache;
        #proxy_cache_bypass $http_cache_control;
        #add_header X-Proxy-Cache $upstream_cache_status;
    }

    location /api/ {
        proxy_pass http://127.0.0.1:3000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }
1

I too think this has to do with client side caching.

I would start debugging this with firebug or something similar, load the page and check the caching headers (etag / last-modified / cache-control / expires).

While we are at this, i found really good this document about HTTP caching:

https://www.mnot.net/cache_docs/

Made from one of the guys that makes the HTTP standard nevertheless.

  • I've checked and the Last-Modified doesn't make sense. I pushed a new version of the html files but the Last-Modified header is showing an old date. Is this my problem? How Nginx calculates this header? – etaiso Jan 20 '16 at 13:22
1

I think this is not a server side caching misconfiguration. Static files are cached by the browser automatically. You need some kind of static file versioning to force the browser to read your modified sources:

<link src="/static/style.css?v=xxxx">
<script language="javascript" type="text/javascript" src="/js/app.js?v=xxxx"></script>
0

In addition to the other answers, have a look at hashbuster, a tool written in python to overcome problems like this. The description reads: "hashbuster is a tool for adding cache-busting query strings to URLs in your HTML files.

If you make lots of changes to live web sites, browser and proxy caches are probably the bane of your existence. If you've ever had to tell a client to clear their browser cache to see your latest code push, then hashbuster is for you."

You could invoke the tool for example via a git post-receive hook on your server.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.