MyDevOps Life#Blog#01- Where is the Nginx Cache which holds back the static content changes?

MyDevOps Life#Blog#01- Where is the Nginx Cache which holds back the static content changes?

Considering there are no Nginx or php-fpm level errors at log.

Scenario: Developer got stuck at Nginx Duck

One of our developer recently made some changes to product image at his local magento2 setup and after uploading this to the production server, he has found the changed are not loading, instead the server still loading the old data. The he has tried the following steps to resolve the issues:

  • m2-cc to clear the magento cache
  • php-cc for php opcache clean
  • restarted the nginx
  • flushed redis db
  • restarted php-fpm
  • restarted varnish

But the problem still not resolved and the old data is still appearing and the changes are not reflecting.

As an architect of this production server, what I did is,

  • removed the root level nginx hard cache from /tmp/disk{1,2,3}
  • Then repeat the steps developer took earlier and problem resolved.
  • How this has worked?

1.1 How this was worked?

  • In our production server architecture, to make the response back to client blazing fast, we have implemented some hard cache technique for static contents at Nginx level in /tmp/disk{1,2,3}.
  • For any request, nignx looks first for a static content and if a static content found there, then doen't matter even if the developer changes the static content, it will be still loading the old content as the static content name were same.

    Example: i.e. the product image is slightly modified, you added an arrow in the image but the image name still remains testProduct.jpeg (the old one). So, there is a probability that the new changes might not be reflecting at client side due to some hard cache issue at our Nginx (though not always the case). If so, then removing the hard cache is the solution.

  • Checkout the commands executed in sequence

> rm -rf /tmp/disk1/*
> rm -rf /tmp/disk2/*
> rm -rf /tmp/disk3/*
> service nginx restart

> redis-cli flushall
> systemctl restart php-fpm
> systemctl restart nginx
> systemctl restart varnish

Note 01: A gimps of our production here

  • Webserver: Nginx
  • In Memory cache: Redis
  • Full Page Cache: Varnish
  • Document Indexing: Elasticsearch
  • Php-fpm enabled
  • Media files are loading through CDN in AWS
  • Nginx is under hard cache architecture for fast response back