Applicable to:
- Plesk for Linux
Question
How to enable leverage browser caching in Plesk?
Answer
- 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:
CONFIG_TEXT: <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>
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:
CONFIG_TEXT: 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
:CONFIG_TEXT: 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
:CONFIG_TEXT: 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 file
/etc/apache2/apache2.conf
:CONFIG_TEXT: FileETag None
-
Apply the configuration changes:
# service apache2 reload
-
Validate the Apache configuration:
# apache2ctl -t
Syntax OK -
Check that the module is loaded:
# apache2ctl -M | grep expires
expires_module (shared)
Additional information
Depending on the type of content that is served, it might be required to enable caching for nginx too since different types of content is served by either nginx, or apache:
Comments
0 comments
Please sign in to leave a comment.