Question
How to enable leverage browser caching in Plesk?
Answer
For particular subscription
- Enable mod_expires: Plesk > Tools & Settings > Apache Web Server, tick expires > OK
- Go to Subscriptions > example.com > Apache & nginx Settings, add below to Additional directives for HTTP and Additional directives for HTTPS sections:
<IfModule mod_expires.c>
ExpiresActive On
FileETag None
ExpiresDefault "access plus 14 days"
ExpiresByType image/jpg "access plus 1 month"
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType text/css "access plus 1 month"
ExpiresByType application/pdf "access plus 1 month"
ExpiresByType text/javascript "access plus 1 month"
ExpiresByType text/x-javascript "access plus 1 month"
ExpiresByType application/javascript "access plus 1 month"
ExpiresByType application/x-shockwave-flash "access plus 1 month"
ExpiresByType text/css "now plus 1 month"
ExpiresByType image/ico "access plus 1 month"
ExpiresByType image/x-icon "access plus 1 month"
ExpiresByType text/html "access plus 1 days"
</IfModule>
For the whole server
First of all, connect to the server using SSH.
For RHEL-based operating systems (CentOS, RHEL, CloudLinux, Virtuozzo Linux 7)
-
Comment the line
LoadModule expires_module modules/mod_expires.so
in the file/etc/httpd/conf.modules.d/00-base.conf
. -
Create the configuration file
/etc/httpd/conf.d/expires.conf
:# vi /etc/httpd/conf.d/expires.conf
-
Insert the following content in it:
LoadModule expires_module modules/mod_expires.so
ExpiresActive on
ExpiresDefault "access plus 14 days"
ExpiresByType image/jpg "access plus 1 month"
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType text/css "access plus 1 month"
ExpiresByType application/pdf "access plus 1 month"
ExpiresByType text/javascript "access plus 1 month"
ExpiresByType text/x-javascript "access plus 1 month"
ExpiresByType application/javascript "access plus 1 month"
ExpiresByType application/x-shockwave-flash "access plus 1 month"
ExpiresByType text/css "now plus 1 month"
ExpiresByType image/ico "access plus 1 month"
ExpiresByType image/x-icon "access plus 1 month"
ExpiresByType text/html "access plus 1 days" -
Add the following line to the file
/etc/httpd/conf/httpd.conf
:FileETag None
-
Apply the configuration changes:
# service httpd reload
-
Validate the Apache configuration:
# httpd -t
Syntax OK -
Check that the module is loaded:
# httpd -M | grep expires
expires_module (shared)
For Debian and Ubuntu
-
Add the following content into the file
/etc/apache2/mods-available/expires.load
:ExpiresActive on
ExpiresDefault "access plus 14 days"
ExpiresByType image/jpg "access plus 1 month"
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType text/css "access plus 1 month"
ExpiresByType application/pdf "access plus 1 month"
ExpiresByType text/javascript "access plus 1 month"
ExpiresByType text/x-javascript "access plus 1 month"
ExpiresByType application/javascript "access plus 1 month"
ExpiresByType application/x-shockwave-flash "access plus 1 month"
ExpiresByType text/css "now plus 1 month"
ExpiresByType image/ico "access plus 1 month"
ExpiresByType image/x-icon "access plus 1 month"
ExpiresByType text/html "access plus 1 days" -
Make a symbolic link to that file in the directory
/etc/apache2/mods-enabled/
:# cd /etc/apache2/mods-enabled/ && ln -s ../mods-available/expires.load expires.load
-
Add the following line to the…