DigitalOcean Cache Control Implementation

How to activate browser cache on digital ocean server. Do I need to activate the cache mod? If yes may I know the steps?

Hi Gaurav,

Which server are you using? Follow below tip accordingly.

  • Apache
# Enable expires module
a2enmod expires
# Restart Apache2 server
service apache2 restart

Now any cache plugin like WP Rocket will be able to take care of this part.

Or if you want manually, add below rule in the .htaccess file in your site public directory /var/www/html

<IfModule mod_expires.c>
  ExpiresActive On

  # Images
  ExpiresByType image/jpeg "access plus 1 year"
  ExpiresByType image/gif "access plus 1 year"
  ExpiresByType image/png "access plus 1 year"
  ExpiresByType image/webp "access plus 1 year"
  ExpiresByType image/svg+xml "access plus 1 year"
  ExpiresByType image/x-icon "access plus 1 year"

  # Video
  ExpiresByType video/mp4 "access plus 1 year"
  ExpiresByType video/mpeg "access plus 1 year"

  # CSS, JavaScript
  ExpiresByType text/css "access plus 1 month"
  ExpiresByType text/javascript "access plus 1 month"
  ExpiresByType application/javascript "access plus 1 month"

  # Others
  ExpiresByType application/pdf "access plus 1 month"
  ExpiresByType application/x-shockwave-flash "access plus 1 month"

Add following code in the server block that you can find at location /etc/nginx/sites-available/

location ~* .(css|gif|ico|svg|jpeg|jpg|js|png)$ {
expires 1y;
# Test Configuration
nginx -t
# Reload NGINX
service nginx reload
  • Cloudflare

Login to Cloudflare > Cache > Browser Cache Expiration > Respecting existing header or set 1 year.


Thanks…One more thing… I used 1 click install, so it automatically installed apache, but a lot of people prefer ngnix. What are the advantages of ngnix over apache.

1 Like

Nginx can handle more concurrent users compared to Apache. This is a good choice for a blog.

For example …

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.