WebTracker.one

 
Login
Site Stats
Tools
Whois
Whois
Email Whois
Fingerprint
Logout
Contact
Lost Password
 
Smiley






JavaScript is disabled by your browser. Many features will not work.












Website Acceleration - Apache Caching

A website can be made faster by accelerating the delivery system. That can be accomplished by caching elements of the website in the server memory.

Enable the four following Apache modules and restart Apache:

sudo a2enmod cache
sudo a2enmod cache_disk
sudo a2enmod expires
sudo a2enmod headers

sudo systemctl restart apache2

You will then need to add directives to your apache2.conf file (for global) or virtual host file (for a specific website).

Here are the directives I added to my webtracker.one-le-ssl.conf host file - the code goes beneath the IfModule and VirtualHost starting lines:

Note: My intent is to primarily cache image files. I do not want to cache html or css because I change them frequently. Further, the caching system was sometimes providing the desktop user with a mobile css file and the phone user with a desktop css file. CacheQuickHandler off CacheRoot '/var/cache/apache2/mod_cache_disk' CacheLock on CacheLockPath /tmp/mod_cache-lock CacheLockMaxAge 5 CacheDirLevels 4 CacheDirLength 5 CacheIgnoreHeaders Set-Cookie CacheIgnoreNoLastMod On CacheIgnoreCacheControl On CacheDisable /login.php #any file that you specifically do not want cached <Location /> CacheEnable disk CacheHeader on CacheDefaultExpire 600 CacheMaxExpire 86400 CacheLastModifiedFactor 0.5 ExpiresActive on ExpiresByType text/html 'access plus 0 seconds' ExpiresByType text/css 'access plus 0 seconds' ExpiresByType image/gif 'access plus 1 year' ExpiresByType image/jpg 'access plus 1 year' ExpiresByType image/jpeg 'access plus 1 year' ExpiresByType image/png 'access plus 1 year' ExpiresByType image/webp 'access plus 1 year' ExpiresByType text/javascript 'access plus 30 days' ExpiresByType application/javascript 'access plus 30 days' ExpiresByType application/x-javascript 'access plus 30 days' ExpiresByType video/mp4 'access plus 1 year' Header merge Cache-Control public FileETag All </Location>
If you want more information on what these settings mean, here are available resources:
ServerLab.ca
IBM
Digital Ocean

If you wish to enable logging, add the following line to your apache2.conf file or virtual host file:

CustomLog /var/log/apache2/cache.log cachelog

And add the following line to your apache2.conf file (you can modify the line as you wish):

LogFormat '%a %v:%p %t %r %{cache-status}e %>s ' cachelog

After this, restart Apache.

sudo systemctl restart apache2

You will then be able to see caching activity by entering the following command:

sudo tail -f /var/log/apache2/cache.log

     * posted by Robert on Fri, Sep 02, 2022

Return to Weblog



© 2023 WebTracker.one
 
➤