Caching issue with Apache; css and html not updating - apache

I've recently setup a vps on Ubuntu 20.04 to host a single website amongst other non-apache related things. I've been attempting to work on my site but it seems that the files are being cached. For instance, I can still access the webpage and stylesheet even though its been deleted. Thus far I've spent a couple hours searching for a solution to this. I've looked through here, this and this. I've also tried the suggestion of one place in adding to my .htaccess as follows:
#Initialize mod_rewrite
RewriteEngine On
<FilesMatch "\.(html|htm|js|css)$">
FileETag None
<IfModule mod_headers.c>
Header unset ETag
Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
Header set Pragma "no-cache"
Header set Expires "Wed, 12 Jan 1980 05:00:00 GMT"
</IfModule>
</FilesMatch>
After adding that, restarting apache but still with no success. I've found other posts seemingly with the same issue as me which talk about editing 000-default.conf but I lack the technical understanding of apache to be able to make informed choices on editing things like that out of fear of breaking something.
I believe that apache caching is my issue but I could well be wrong. I can't think of what else it would be though. I think this is an issue I've had in the past but I don't remember the solution. Thanks for any help

Adding ?v=1.x.x to the end of the stylesheet URL fixed the issue. Credit to a Reddit user here

Related

Apache2 no cache specific file only

I'm running and Amazon EC2 with Ubuntu 14.4 and Apache2 with no PHP or other server-side script--just a static content site. I used this tutorial to get to the point I am at now with the apache file (see screenshot at link below):
https://www.digitalocean.com/community/tutorials/how-to-configure-apache-content-caching-on-ubuntu-14-04
I want to have a directive (if that is the nomenclature) that tells Apache to not cache a single, specific file only, but still handle everything else as it is already configured. I'm no computer whizz here--just learning. Is there a way to do this? Currently I have made a new directory inside my images folder called "no-cache" where the image I do not want cached lives.
I tried adding a second location tag below the first one with "CacheDisable on" inside it, however this is not supported. Also tried using a Directory tag, but this also does not work with the current configuration.
Thanks in advance!
/etc/apache2/sites-enabled/000.default.conf
The link you provided is a bit confusing since it mentions so many different types of caching.
When dealing with Webservers and caching, what you usually mean is sending cache messages (using http headers) to define how the browser should handle caching, to improve visitors performance. This is the last item discussed in that link of yours, despite being the most common. The first section talks about Apache caching files itself to improve its own performance and is much less common.
If client side caching using mod_expiries is what you mean, then you can control this with location headings:
#Allow long term assets to be cached for 6 months as they are versioned and should never change
<Location /assets/libraries/ >
ExpiresDefault A15724800
Header set Cache-Control "public"
</Location>
#Do not cache these files
<Location /login >
Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
Header set Pragma "no-cache"
</Location>
I've a more detailed blog on this here: https://www.tunetheweb.com/performance/http-performance-headers/caching/.

How to Change Response Headers - Pragma & Cache-Control

I'm using Font Awesome in my web application but none of my icons are displaying in Internet Explorer 11. Per their troubleshooting guide
I learned that this behavior can be tied to the no-store Cache-control header, or the no-cache Pragma header.
How can I change these header values?
Ideally, there would be some option in the IE developer tools where I can adjust this, but this does not seem possible. I have been playing around on my web server - Apache 2.4 (Debian) - and attempted the following in my sites-enabled configuration:
<FilesMatch "\.(eot|woff|ttf|svg|otf)$">
<ifModule mod_headers.c>
Header unset Cache-Control
Header unset Pragma
</ifModule>
</FilesMatch>
I reloaded Apache and no change, these Headers are still set, my icons are still not displayed in Internet Explorer.
I don't have that much experience with Apache, I could really use some help here! Thanks in advance.

If an image/file is changed, does the header expire?

This is probably a dumb question but I couldn't find an answer anywhere.
I recently added mod_deflate and cache control to my htaccess:
<FilesMatch "\.(txt|xml|js|css)$">
Header set Cache-Control "max-age=604800"
</FilesMatch>
My question was, if I update a CSS sheet, will my visitors' browser figure out that it's been modified or will it completely ignore it and won't grab it again until it expires (a week after) ?
Thanks

Why is this FilesMatch not matching correctly?

We have been attempting to configure our server not to cache our .htm files as it is causing a few issues with our analytics package as well as not displaying the pages correctly if the visitor hits the back button in their browser.
We have attempted to tackle it by adding:
<FilesMatch "\.(htm)$">
Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
Header set Pragma "no-cache"
Header set Expires "Wed, 11 Jan 1984 05:00:00 GMT"
Header set Warning "Testing"
</FilesMatch>
to our httd file but it does not appear to execute, however, when we move the Header set outside of the FilesMatch it appears to execute fine..
Anyone have any ideas where we are going wrong?
I recently needed to figure out the same kind of problem and, although this post pointed me in the right direction, I wanted to share some clarifying information for the edification of those who search on this topic in the future.
David, your initial FilesMatch was not working because FilesMatch only works on real, physical files that exist on your filesystem. http://httpd.apache.org/docs/current/sections.html states it as:
The Directory and Files directives, along with their regex counterparts, apply directives to parts of the filesystem.
This is also why your second post using LocationMatch resolved the issue. Also from http://httpd.apache.org/docs/current/sections.html, it states:
The Location directive and its regex counterpart, on the other hand, change the configuration for content in the webspace. < SNIP > The directive need not have anything to do with the filesystem. For example, the following example shows how to map a particular URL to an internal Apache HTTP Server handler provided by mod_status. No file called server-status needs to exist in the filesystem.
<Location /server-status>
SetHandler server-status
</Location>
The Apache docs summarizes this behavior with the following statement:
Use Location to apply directives to content that lives outside the filesystem. For content that lives in the filesystem, use Directory and Files. An exception is < Location / >, which is an easy way to
apply a configuration to the entire server.
For those that want to understand more of the mechanics, this is how I understand the internals:
Location directives match based on the HTTP request URI (e.g. example.com/this/is/a/uri.htm without the example.com part).
Directory and Files directives, on the other hand, match based on whether there is a directory path or file in the filesystem of the DocumentRoot that matches to respective part of the the HTTP request URI
The Apache docs summarizes this behavior as:
What to use When
Choosing between filesystem containers and webspace containers is actually quite easy. When applying directives to objects that reside in the filesystem always use Directory or Files. When applying directives to objects that do not reside in the filesystem (such as a webpage generated from a database), use Location.
[IMPORTANT!] It is important to never use Location when trying to restrict access to objects in the filesystem. This is because many different webspace locations (URLs) could map to the same filesystem location, allowing your restrictions to be circumvented.
This issue has now been resolved.
In order to get it to work we have changed from using FilesMatch to LocationMatch and now the headers are being set perfectly.
We believe this is because the page is being redirected from a JSP page to an HTML page.
<LocationMatch "\.(htm|html)$">
Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
Header set Pragma "no-cache"
Header set Expires "Wed, 11 Jan 1984 05:00:00 GMT"
Header set Warning "Testing"
</LocationMatch>
Hopefully others will find this helpful.

How can I stop Joomla (Apache) from caching the admin backend?

I've a big cache issue with my Joomla 1.5.26 (Apache/2.2.14 Ubuntu) administrator panel.
Everything is cached for about 15 minutes, and by everything I mean everything.
If I go to global configuration and change any value there, for example the Site Name from "MyTestSite" to "MyTestSite2", or the Feed length from 15 to 30 and save it a message is displayed that everything was saved and the cache was cleaned. If I go immediately to the global config again, I see that the old values (MyTestSite and 15) are still there. If I look into configuration.php I see that the file was correctly changed. Also, if I wait 15 minutes I can see the correct value. This is not related only to configuration, but even to article editing!
It's the same on 2 computers, and with Firefox, Chrome, and IE.
I've tried to fix it by placing a .htaccess in /admistrator/ to disable any caching, but to no avail.
I've tried this:
<ifModule mod_headers.c>
Header unset ETag
Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
Header set Pragma "no-cache"
Header set Expires "Wed, 11 Jan 1984 05:00:00 GMT"
</ifModule>
or this:
ExpiresActive On
ExpiresDefault "access plus 1 minute"
What is going on here? (it was working fine for 2 years). How can I stop Joomla from caching the admin backend?