RE: Prevent caching of 404 responses

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Thanks for the responses, including the info about what response codes are cachable. My expectations would have been that 404's wouldn't have been cached, but was questioning / doubting this assumption / expectation as I'm struggling to explain the behaviour being reported:
User reports their web page is showing a 404 error.
Helpdesk looks at page, sees same 404 error (presumably having never visited this in their browser before).
Helpdesk reloads web-page (Shift-Refresh), and get 200 response, returning page content as expected.

From the access logs I can see a 404 response was returned. I don't see any corresponding issues in the error-log, or anything to suggest problems with the mount in the system logs.

This has happened at least twice in the last two days. I've never encountered any problems like this with content not appearing from the NFS exports from our SAN.

Unfortunately I don't have the headers for a page that should have existed where a 404 response resulted. I've requested that this is captured next time this reoccurs.

If I request a page that doesn't exist from the same area, the headers reported by Firefox's Live-HTTP-Headers return a 404 response code, as follows (hostname changed).

GET /~user/test2.htm HTTP/1.1
Host: host.domain.com
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:35.0) Gecko/20100101 Firefox/35.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Connection: keep-alive

HTTP/1.1 404 Not Found
Date: Thu, 26 Feb 2015 13:11:34 GMT
Server: Apache
Strict-Transport-Security: max-age=31536000; includeSubDomains
Accept-Ranges: bytes
Keep-Alive: timeout=3, max=100
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: text/html

Thanks,
Paul


> Date: Thu, 26 Feb 2015 13:23:41 +0100
> From: ylavic.dev@xxxxxxxxx
> To: users@xxxxxxxxxxxxxxxx
> Subject: Re: [users@httpd] Prevent caching of 404 responses
>
> On Thu, Feb 26, 2015 at 1:00 PM, Yann Ylavic <ylavic.dev@xxxxxxxxx> wrote:
> > On Thu, Feb 26, 2015 at 10:21 AM, Paul Beckett <paul_beckett@xxxxxxxxxxx> wrote:
> >> Is there any way to restrict what HTTP response codes are cached by Apache,
> >> ideally I would like to only cache 200,301,302 responses.
> >
> > It is not possible to specify some particular status mod_cache would
> > or not cache, it is solely controlled by the relevant Cache-Control
> > and Expires headers.
> > (Note that 301 will not be cached unless "forced" by these headers).
>
> Hmm, I forgot about the RFC and mod_cache's code (and I meant 302 above)...
>
> Actually, mod_cache won't cache anything but 200, 203, 206, 300, 301
> or 410 (as per RFC), unless otherwise specified by Cache-Control
> (public, ...) or Expires (future date) headers.
>
> So you probably have one of these in your response (mod_expires sets
> Expires if you use it, but it has been fixed in 2.4.10 not to for
> 4xx/5xx responses precisely, and you are already in 2.4.10...).
>
> The mod_headers rules below should not be needed then, what are the
> headers associated with the 404?
>
> >
> > You could use some mod_headers rule(s) like :
> > Header merge Cache-Control private "expr=%{REQUEST_STATUS} == 404"
> > Header merge Pragma no-cache "expr=%{REQUEST_STATUS} == 404"
> > to prevent mod_cache (but also other caches down the chain) from
> > caching eg. 404s.
> >
> > Regards,
> > Yann.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@xxxxxxxxxxxxxxxx
> For additional commands, e-mail: users-help@xxxxxxxxxxxxxxxx
>

[Index of Archives]     [Open SSH Users]     [Linux ACPI]     [Linux Kernel]     [Linux Laptop]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Squid]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]

  Powered by Linux