Caching Static Content with Cloudways

Cloudways offers a convenient web interface that simplifies the system administration tasks involved in deploying and hosting a website, while still providing access to the Linux command line for advanced users. However, as with any convenience, there can be compromises.

Recently, I migrated some personal websites from Digital Ocean to a single Digital Ocean backed server at Cloudways, including the site you’re reading right now. While this site is built on a Cloudways WordPress application, it also hosts some static content that isn’t part of the WordPress environment. Namely, the sky cams and weather station data pages, which are updated every 5 minutes from servers at my home.

After successfully migrating the weather data and sky cams to Cloudways, I noticed that the caching seemed too persistent. Even after several days, the weather page and camera images would not update automatically from the last time they were viewed.

Initially, I disabled Varnish caching for the affected directories, but this did not solve the problem. I then attempted to modify the caching-related Apache directives in the .htaccess files, but these directives only affected the response headers for the directories themselves, not for the files, which were set to expire after 30 days.

The root of the problem was my lack of understanding the hosting environment. I’d assumed that Apache was serving all content, but in reality, it’s a hybrid of Apache and Nginx. Apache serves the dynamic content, while Nginx handles the static content.

After some investigation, I discovered the “Static Cache Expiry” setting, which was only available at the server level and not on a per-application or per-site basis. As Nginx does not have an .htaccess equivalent, there was no way to override this setting on a per-directory basis. Cloudways support confirmed that the single setting applied to the entire server and could not be modified.

The idea of setting static caching to 5 minutes for every directory and every site simply to accommodate two isolated situations was not an optimal solution. While I could move the static content to a regular LAMP server at Digital Ocean or Vultr, I preferred to keep everything together on Cloudways.

It would be beneficial if Cloudways offered alternative solutions, such as the ability to serve static content using Apache with Google PageSpeed or other options.