On your OpenLiteSpeed servers, there are 2 files that you can use to override expires by type at the server level or on a per-site basis:
- Server level:
- Site level:
The server-level file is pre-populated with the defaults. The site-level file doesn’t exist by default.
The default time is 1 year (31535990). You can change this to any time you’d prefer.
Below are the steps to get started.
Step 2. Get Your MIME TypeThe following command will show a list of acceptable MIME types directly on the server:
gpols get mimeFor quick reference, here’s the list:
Step 3. Custom ExpiresByType Formatting
Steps 4a and 4b below detail how add your custom ExpiresByType. In both cases, the formatting is the same when editing their respective files.
The above list will give you the beginning you need. For example to target a jpeg/jpe/jpg file, you can use the following to set it to half a year (in seconds):
Wildcards will also work, for example, to target all image types you could use the following:
Add one rule per line.
Step 4a. Add Your Custom ExpiresByType at the Server Level
To change this at the server level, edit the server config with this command:
You’ll see the following:
To add additional rules, add each on their own line.
Once you’ve made your edits, save the file with CTRL+O and then Enter, and then exit nano with CTRL+X. Now regenerate server conf and restart OpenLiteSpeed with:
Step 4b. Add Your Custom ExpiresByType for an Individual Site
To add custom ExpiresByType for an individual website, run the following command (replacing site.url with your URL):
Add one rule per line, and once you’ve made your edits, save the file with CTRL+O and then Enter, and then exit nano with CTRL+X.
Now reload the OpenLiteSpeed configuration with (replacing site.url with your sites URL) to set your changes live:
gpols site site.url
Check Your Work
First, open up your website in an incognito window. Next, right-click and choose “Inspect“, select the “Network” tab, and then reload the page.
Now you can select your filetype from the lefthand column. In the images below you can see the cache-control max-age (which will display the expiry time you’ve just made) and the content type.
Here’s an example of a .png file:
Here’s an example of a CSS file: