Leverage browser caching

Questions about HTTP Access/Mods may go here
Forum rules
We've moved! Head over to Synology Community (community.synology.com) to meet up with our team and other Synology enthusiasts!
Posts: 13
Joined: Wed Mar 13, 2013 1:51 pm

Leverage browser caching

Unread post by Lumies » Sat May 16, 2015 8:06 am

I'm trying to set up Leverage browser caching for my website. GTmetrix shows that I don't have it. Here's what's in my .htaccess file. I think it should work like that, but is there something else than .htaccess what should be enabled? .htaccess file is in web site's root folder (volume1/web/site/).
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access plus 1 year"
ExpiresByType image/jpeg "access plus 1 year"
ExpiresByType image/gif "access plus 1 year"
ExpiresByType image/png "access plus 1 year"
ExpiresByType text/css "access plus 1 month"
ExpiresByType application/pdf "access plus 1 month"
ExpiresByType text/x-javascript "access plus 1 month"
ExpiresByType application/x-shockwave-flash "access plus 1 month"
ExpiresByType image/x-icon "access plus 1 year"
ExpiresDefault "access plus 2 days"

Posts: 15
Joined: Sat Jan 17, 2015 2:11 am

Re: Leverage browser caching

Unread post by maneuss » Sat May 16, 2015 10:29 pm


i´ve got the same problem. it seems that mod_expires is not included in the webserver. :(

(checked for installed modules after logging in via ssh and using the httpd -M command to check for installed modules (list below).)
at least mod_rewrite (necessary for redirections eg. in joomla) and mod_deflate (automatic compression of content) are available.

i will issue a support ticket to synology. hopefully mod_expires is included in one of the next dsm updates.


list of installed modules (as issued by httpd -M) on my ds411+

HomeNAS> httpd -M
Loaded Modules:
core_module (static)
mpm_worker_module (static)
http_module (static)
so_module (static)
authn_file_module (shared)
authn_default_module (shared)
authz_host_module (shared)
authz_groupfile_module (shared)
authz_user_module (shared)
authz_owner_module (shared)
authz_default_module (shared)
auth_basic_module (shared)
auth_digest_module (shared)
include_module (shared)
filter_module (shared)
deflate_module (shared)
log_config_module (shared)
env_module (shared)
mime_magic_module (shared)
headers_module (shared)
setenvif_module (shared)
proxy_module (shared)
proxy_http_module (shared)
mime_module (shared)
status_module (shared)
autoindex_module (shared)
asis_module (shared)
cgid_module (shared)
negotiation_module (shared)
dir_module (shared)
actions_module (shared)
userdir_module (shared)
alias_module (shared)
rewrite_module (shared)
xsendfile_module (shared)
reqtimeout_module (shared)
suphp_module (shared)
Syntax OK

Posts: 15
Joined: Sat Jan 17, 2015 2:11 am

Re: Leverage browser caching, mod_expires, dsm 5.2

Unread post by maneuss » Sun May 17, 2015 12:11 am

sorry, was so excited that solution was working that i wrote the answer in my native language (german). so i´ll try to translate in english (and shorten the answer a little bit).

at first: all necessary files are available with dsm 5.2. the error is that mod_expires is not included in te config file, so it is not loaded when the webserver starts up. the change is rather simple. only problem might be that the config file might be overwritten when a system update takes place.

disclaimer: i will take no responsibility when your changes will lead to a non-functioning webserver or worse.

login to your disk station using a terminal-app and ssh with root account e.g.
ssh root@ (or when the port number has changed to e.g. 12000 ssh root@ -p 12000)

enter the admin password (the same as for the admin account)

check, if mod_expires is already present:
httpd -M
prints a list of installed modules. check for a module named mod_expires or expires_module.

if not installed go to conf-directory
cd /etc/httpd/conf

backup conf-file
cp httpd.conf httpd_conf.bak

edit with vi
vi httpd.conf

or copy to another directory (e.g. your home directory) edit with a text editor and copy back. e.g. with
cp httpd.conf /volume1/homes/Name/httpd.conf
(insert appropriate names for volume1 and Name)
edit with a text editor on your computer, save and copy back to the config-directory
cp /volume1/homes/Name/httpd.conf httpd.conf

regardless of type of editing you only have to add the command to load the expires-module when starting up the webserver. all modules are loaded at the beginning of the config-file:
"... LoadModule alias_module modules/mod_alias.so
LoadModule rewrite_module modules/mod_rewrite.so
... "
after the list just add the command
LoadModule expires_module modules/mod_expires.so
now the expires module (located at /etc/httpd/modules/mod_expires.so) will be loaded when the server restarts.

save and quit vi with :wq or copy back the file as described above
if you want you can check the changed file with
cat httpd.conf
or test the syntax of the config file with
httpd -t
the result should be SYNTAX OK

now the weserver has to be restarted with
httpd -k restart
after a short time you can check the loaded modules with
httpd -M.

worked wonderfully. now browser caching is enabled. google pagespeed is not content with some of the time limits specified in .htaccess but that will be adapted

greetings martin

ps vi:

command reference at http://de.wikibooks.org/wiki/Vi-Befehls ... earbeitung
how to use in short:
vi httpd.conf
opens the file in command mode
with the cursor keys move to the line after the LoadModules commands
the key "i" changes to insert mode
enter "LoadModule expires_module modules/mod_expires.so". press return for new line.
ESC returns to command mode
key combination :wq (colon wq) writes back the chenged file and exits vi


Return to “HTTP/Apache Mods”