refactor: Consolida lógica de cache e remove cache de documentos (PDF)
This commit is contained in:
parent
e2c8f954ad
commit
0e2581dd18
|
|
@ -7,23 +7,22 @@ proxy_cache_background_update on;
|
|||
proxy_cache_use_stale error timeout updating http_500 http_502 http_503 http_504;
|
||||
|
||||
# 2. Configurações de Cache-Control por Tipo de Arquivo
|
||||
# Nota: $cache_asset_ttl vem do security_maps.conf
|
||||
add_header X-Cache-Status $upstream_cache_status;
|
||||
|
||||
# Trata HTML: Cachear mas sempre perguntar ao servidor se mudou (no-cache)
|
||||
# Isso permite o 304 Not Modified, evitando download desnecessário mas garantindo atualização.
|
||||
map $sent_http_content_type $cache_control_header {
|
||||
default "no-cache, no-store, must-revalidate";
|
||||
~*text/html "no-cache, must-revalidate";
|
||||
~*application/json "no-cache, must-revalidate";
|
||||
~*(image|audio|video|font) "public, max-age=31536000, immutable";
|
||||
~*(text/css|javascript) $asset_cache_policy;
|
||||
}
|
||||
|
||||
# 3. Política Diferenciada para JS/CSS
|
||||
# Se tiver versão (?v= ou .v1.) -> Cache Eterno
|
||||
# Se for nome limpo -> Cache curto com revalidação obrigatória
|
||||
map $request_uri $asset_cache_policy {
|
||||
# Trata a política de Cache do Navegador baseado na URI e Versão
|
||||
map $request_uri $cache_control_header {
|
||||
# 1. Assets Versionados -> Imutáveis (1 ano)
|
||||
~*(\?v=|\?id=|\.v[0-9]|\.[0-9a-f]{8,}) "public, max-age=31536000, immutable";
|
||||
default "public, max-age=3600, must-revalidate";
|
||||
|
||||
# 2. Assets Comuns (Imagens, Fontes) -> Revalidação obrigatória (curto)
|
||||
~*\.(webp|avif|heic|apng|jpg|jpeg|gif|png|ico|svg|woff2?|ttf|otf|eot)$ "public, max-age=86400, must-revalidate";
|
||||
|
||||
# 3. Scripts e Estilos (Sem versão) -> Revalidação agressiva (curto)
|
||||
~*\.(mjs|js|ts|wasm|json|css|less|scss)$ "public, max-age=3600, must-revalidate";
|
||||
|
||||
# 4. HTML e APIs -> Nunca cachear no navegador sem revalidar
|
||||
~*(\.html|\/api\/) "no-cache, must-revalidate";
|
||||
|
||||
# Padrão: Segurança Máxima (Documentos, PDFs, etc. não são cacheados)
|
||||
default "no-cache, no-store, must-revalidate";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -116,13 +116,19 @@ map $security_score $heavy_limit_key {
|
|||
# 3. Cache Asset TTL - Suporte Total 2026 (Modern Web)
|
||||
# No proxy_cache usamos um tempo curto, o Cache-Control (Browser) é que decide o tempo longo.
|
||||
map $request_uri $cache_asset_ttl {
|
||||
# Imagens e Mídia
|
||||
# 1. Assets Versionados (?v= ou .v1.) -> Cache Longo no Proxy (1 mês)
|
||||
~*(\?v=|\?id=|\.v[0-9]|\.[0-9a-f]{8,}) 30d;
|
||||
|
||||
# 2. Imagens e Mídia (Sem versão) -> 1 dia
|
||||
~*\.(webp|avif|heic|apng|jpg|jpeg|gif|png|ico|svg)$ 1d;
|
||||
# Scripts e Estilos (Revalidação rápida no Proxy)
|
||||
|
||||
# 3. Scripts e Estilos (Sem versão) -> 6 horas
|
||||
~*\.(mjs|js|ts|wasm|json|css|less|scss)$ 6h;
|
||||
# Fontes e Documentos
|
||||
~*\.(woff2?|ttf|otf|eot|pdf)$ 7d;
|
||||
# Padrão: Sem Cache
|
||||
|
||||
# 4. Fontes -> 7 dias
|
||||
~*\.(woff2?|ttf|otf|eot)$ 7d;
|
||||
|
||||
# Padrão: Sem Cache (Documentos como PDF entram aqui por segurança)
|
||||
default off;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue