Need help? Call us on 1300 789 260

Enable content expiry cache headers for nginx

Difficulty: Intermediate

Prerequisites

Access to your Plesk server

Overview

In order to let browsers explicitly know to keep a copy parts of your website, you can set content-expiry headers within nginx. This means that subsequent page loads or revisits within the expiry time, the browser doesn't have to reload these files. This is best set for static media (ie CSS files, images and similar), which can in most instances be safely cached.

Instructions

  1. Login to your Plesk server and select the domain you wish to set the content expiry headers for.
  2. Under the domain, select "Apache and nginx settings":
  3. In the bottom "Additional nginx directives" field, add the following:
    location ~* \.(?:ico|css|js|gif|jpe?g|png|svg|woff)$ {
    	expires 30d;
    	add_header Pragma public;
    	add_header Cache-Control "public";
    }

    This sets all icons, css, js, images and fonts to cache for 30 days.

  4. Click OK to save and apply.

You can verify these headers are now working by using your browser's debug tools or a third party website such as GTMetrix .

Was this article helpful? Yes No
👥

Having trouble? We’re here to help!

We’ve built our company with a serious focus on quality service. Feel free to give us a call!

1300 789 260