Managing DreamPress cache with the Nginx Helper plugin

 

Overview

The Nginx Helper plugin is automatically configured with all DreamPress websites. This plugin helps to avoid issues such as the inability to view saved changes or displaying outdated content to visitors. 

This article explains how to use the plugin's caching features on your DreamPress site. 

Caching methods

The Nginx Helper provides two caching options:

  • nginx Fastcgi cache: Manages external settings for Nginx
  • Redis cache: This functionality is not available on DreamPress

The instructions in this article assume the latest version of the Nginx Helper plugin is active. Make sure this plugin is up to date before proceeding or if you encounter difficulties with these steps.

Installing and activating the Nginx Helper plugin

  1. Log into your WordPress site at example.com/wp-login.php.
  2. In the left menu, navigate to Plugins > Add New.
  3. Search for Nginx Helper.
  4. Click the Install Now and Activate buttons.

    If the Active button is grayed out, navigate to the Plugins > Installed Plugins page. Confirm that the plugin is listed here and active.

The plugin is automatically configured for you, so no further adjustments are required.

Overwriting the plugin

It's possible that this plugin may have been overwritten at some point in the past. The following actions may cause this to happen:

  • Migrating a WordPress website from another hosting company to DreamPress
  • Uploading a WordPress website from your computer to DreamPress

If the plugin is removed, you are always able to install it again in the WordPress dashboard.

Activating cache settings

The Nginx Helper plugin gives you fine-grained control over the management and deletion of your site’s cache, as well as access to debug configuration options.

To access this settings screen:

  1. Log into your WordPress site at example.com/wp-login.php.
  2. In the left menu, select Settings > Nginx Helper.
  3. In the Debug Options section, check the boxes for:
    • Enable Logging
    • Enable Nginx Timestamp in HTML
  4. Click Save All Changes to save the new settings.

Enable Logging

This setting creates a log file that contains the latest events from actions such as clearing cache, warnings, and error messages. This log file is located in the following directory:

example.com/wp-content/uploads/nginx-helper/nginx.log

Enable Nginx Timestamp in HTML

This setting creates a hidden comment at the end of every page. This contains:

  • The date
  • Number of queries
  • Time it takes to generate a static version of the webpage

You can view this hidden comment by viewing the page's source code in your browser:

  • Windows: Ctrl + U
  • Mac: Option + CMD + U

Scroll down to the last line at the bottom of the HTML code to view this information. It will appear like this:

<!--Cached using Nginx-Helper on 2024-04-09 15:20:14. It took 12 queries executed in 0.289 seconds.-->

Use this information before and after a manual purge to test that the cache is working properly.

Testing cache via SSH

The following SSH commands allow you to test your site's cache.

Log into your website via SSH to run the following commands.

In the following examples, replace example.com with your website.

Use curl -I to test your website URL. This could either be the www or non-www version of your website:

  • https://example.com
  • https://www.example.com

Whichever URL your website is using, make sure to run the command at least twice. For example:

[server]$ curl -I https://example.com

Reading the output

This command outputs various HTTP Headers. You are looking for the x-cache-status header.

If it is hit on the second attempt, the page is being cached as expected. For example:

[server]$ curl -I https://example.com
HTTP/2 200
server: nginx
date: Tue, 09 Apr 2024 16:48:49 GMT
content-type: text/html; charset=UTF-8
vary: Accept-Encoding
vary: Accept-Encoding, Cookie
cache-control: max-age=3, must-revalidate
strict-transport-security: max-age=31536000;
x-cache-status: MISS

[server]$ curl -I https://example.com
HTTP/2 200
server: nginx
date: Tue, 09 Apr 2024 16:48:49 GMT
content-type: text/html; charset=UTF-8
vary: Accept-Encoding
vary: Accept-Encoding, Cookie
cache-control: max-age=3, must-revalidate
strict-transport-security: max-age=31536000;
x-cache-status: HIT

Purging the cache

Using the plugin

It's recommended you only purge the cache when troubleshooting issues, as caching is beneficial to your site.

Purge ALL cache

  1. Log into your WordPress site at example.com/wp-login.php.
  2. In the left menu, select Settings > Nginx Helper.
  3. On the top right, click the Purge Entire Cache button.

Purge a single page or post

A better alternative is to selectively purge the cache of a specific page or post. You can purge a page or post from the cache using the plugin's Purge Cache button when you view the live page.

To purge cache for an individual page or post:

  1. Log into your WordPress site at example.com/wp-login.php.
  2. Navigate to the page or post you want to purge from the cache.
  3. Click the View link under the title to open the public URL.
  4. In the toolbar at the top, click Purge current Page.
    The page reloads, and the page or post is purged from the cache.

Using SSH

In the following examples, replace example.com with your website.

Log into your website via SSH to run the following commands.

Purge ALL cache

This purges the cache for your entire website:

[server]$ curl -X PURGE -D - https://example.com/*

Purge a single page's cache

This purges the cache for a specific page:

[server]$ curl -X PURGE -D - https://example.com/page1

Troubleshooting DreamPress cache issues

If the Nginx Helper plugin doesn't seem to be working, there are several things you can test.

The following steps require technical familiarity with your DreamPress site. Please contact support if you require any assistance with this troubleshooting process.

Delete the /cache folder

If your site uses any additional caching plugins, delete the contents of your /wp-content/cache folder.

Disable Proxy Services

Proxy services like Cloudflare can cause false positives with page caching. DreamHost recommends temporarily disabling any proxy services when troubleshooting issues with your server caching.

Switch to a default theme

The first and simplest thing to test is your site's theme:

  1. Log into your WordPress site at example.com/wp-login.php.
  2. In the left menu, navigate to Appearance > Themes.
  3. Change the active theme to a default theme (such as twentytwentythree).
  4. Test the cache again.

Disable your plugins

DreamHost recommends backing up your site's database before making these changes.

Use the steps below to test your site's active plugins:

  1. Make sure you have enabled the cache settings Enable Logging and Enable Nginx Timestamp in HTML as explained above.
  2. Disable all plugins except for Nginx Helper.
  3. Purge the cache using the plugin or via SSH.
  4. Visit your website in a browser.
  5. Load the page in a browser you want to troubleshoot.
  6. Open the page source and check the Nginx Timestamp in the HTML code.

Locating the plugin responsible

If disabling plugins results in your site's caching service working again, that means there is a plugin that is the most likely cause of the cache issues.

To determine which plugin is responsible:

  1. Rename each plugin one at a time.
  2. Purge the cache using the plugin or via SSH.
  3. Visit your website in a browser.
  4. Load the page in a browser you want to troubleshoot.
  5. Open the page source and check the Nginx Timestamp in the HTML code.

If any disabled plugins are necessary for your site's intended functionality, you must contact the plugin developer to find a workaround to work with the site's cache.

Bypass the cache on a single page

You can bypass the cache on a single page by adding ?nocache to the end of the URL. For example:

example.com/?nocache
example.com/sample-page/?nocache

See also

Did this article answer your questions?

Article last updated PST.

Still not finding what you're looking for?