Created
June 3, 2025 03:15
-
-
Save adamz01h/d06c3dc1058b47c786f201a7e23f3409 to your computer and use it in GitHub Desktop.
makes a small ram drive for server cache
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| ##Ubuntu 24.04.2 LTS | |
| CONF_FILE="/etc/apache2/conf-available/cache.conf" # Set your filename here | |
| ramdrive=512M | |
| a2enmod cache | |
| a2enmod cache_disk | |
| a2enmod headers | |
| a2enmod expires | |
| ####RAM DISK caching | |
| sudo mkdir -p /mnt/ramdisk | |
| sudo echo "tmpfs /mnt/ramdisk tmpfs defaults,size=$ramdrive 0 0" >> /etc/fstab | |
| sudo mount /mnt/ramdisk | |
| systemctl daemon-reload | |
| # enable caching for all requests; cache content on local disk | |
| cat <<EOF > $CONF_FILE | |
| <IfModule mod_cache.c> | |
| CacheEnable disk / | |
| CacheRoot /mnt/ramdisk | |
| # common caching directives | |
| CacheQuickHandler off | |
| CacheLock on | |
| CacheLockPath /tmp/mod_cache-lock | |
| CacheLockMaxAge 5 | |
| CacheHeader On | |
| # cache control | |
| CacheIgnoreNoLastMod On | |
| CacheIgnoreCacheControl On | |
| # unset headers from upstream server | |
| Header unset Expires | |
| Header unset Cache-Control | |
| Header unset Pragma | |
| # set expiration headers for static content | |
| ExpiresActive On | |
| ExpiresByType text/html "access plus 1 years" | |
| ExpiresByType image/png "access plus 1 years" | |
| ExpiresByType application/javascript "access plus 1 years" | |
| </IfModule> | |
| EOF | |
| sudo a2enconf cache | |
| sudo systemctl reload apache2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment