Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

435
Visualizações
Apache Virtual Host Reverse Proxy Specific URL: How to correctly cache on local server and client?

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:

  • https://httpd.apache.org/docs/2.4/howto/reverse_proxy.html
  • https://taylor.callsen.me/creating-a-caching-proxy-server-with-apache/

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!

over 4 years ago · Santiago Trujillo
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda