I posted this question on the Apache httpd-users mailing list a week ago, no response there. Since then, I've done a bit more work, so I hope I can get some help here, thanks!
In my Apache Virtual Host, I have a working reverse proxy for specific URLs. My use case: I use plausible.io for privacy-respecting web stats. See Plausible's discussion of the need for the proxy. Here's that part of my config:
SSLProxyEngine on
ProxyPass "/api/event" "https://plausible.io/api/event"
ProxyPass "/p.js" "https://plausible.io/js/plausible.js"
Here's the location on my web site, serving the Javascript from Plausible: https://pseud.ony.ms/p.js
The response includes:
cache-control: max-age=0, private, must-revalidate
Now I'd like to work out how to configure my local server to cache the Javascript file and serve it with appropriate headers, like Expires, Last-Modified, Cache-Control, etc., and respond 304 when appropriate.
I've consulted the Apache documentation and read some cookbook articles on reverse proxies and caching with Apache, including:
But those describe a server where everything is reverse-proxied. I want to proxy and cache only these few locations.
I spent some time coming up with these directives in my virtual host (not active as I write this, since they don't work):
ExpiresActive On
ExpiresByType application/javascript "access plus 1 years"
# CacheRoot directory created by a2enmod cache_disk
CacheRoot /var/cache/apache2
CacheQuickHandler off
CacheLock on
CacheLockPath /tmp/mod_cache-lock
CacheLockMaxAge 5
CacheIgnoreCacheControl On
CacheHeader On
Header unset Expires
Header unset Cache-Control
Header unset Pragma
CacheEnable disk /p.js
SSLProxyEngine on
ProxyPass "/api/event" "https://plausible.io/api/event"
ProxyPass "/p.js" "https://plausible.io/js/plausible.js"
With those directive activated, the response loses the Cache-Control header and now includes:
X-Cache: MISS from pseud.ony.ms
Even when I refresh the browser, which is when I'd like to see a 304 response or at least a cache hit.
Oh, and is there a way I can confirm Apache is sending X-Forwarded-For to Plausible, so they can geolocate the IP address correctly?
Thanks!