[Auto-Sync] Atualização das configurações em srvproxy001.itguys.com.br - 2025-10-01 21:51:49

This commit is contained in:
srvproxy001.itguys.com.br 2025-10-01 21:51:49 -03:00
parent ef24600a46
commit a336fbe39b
1 changed files with 104 additions and 282 deletions

View File

@ -1,31 +1,3 @@
# ==========================================================================================
# ARQUIVO: /etc/nginx/sites-available/cloud.grupopralog.com.br.conf
# DATA DA ALTERAÇÃO: 2025-09-27 13:45
#
# AUDITORIA E OTIMIZAÇÃO POR GEMINI
# VERSÃO: 11.0 (Refatorado para Estrutura Global)
#
# MELHORIAS APLICADAS NESTA VERSÃO:
# 1. REMOÇÃO DE DIRETIVAS GLOBAIS:
# - As diretivas 'geo', 'map', 'limit_req_zone' e 'proxy_cache_path' foram removidas
# deste arquivo, pois agora são gerenciadas centralmente em /etc/nginx/nginx.conf.
#
# 2. INTEGRAÇÃO COM MÓDULO DE SEGURANÇA GLOBAL:
# - Substituídos os antigos blocos 'if' e 'location' por uma única verificação
# da variável '$block_request', definida no nginx.conf.
#
# 3. CONFIGURAÇÃO ALINHADA E SIMPLIFICADA.
# ==========================================================================================
# ======================================================================
# LÓGICA DE WHITELIST E RATE LIMIT MOVIDA PARA /etc/nginx/nginx.conf
# ======================================================================
# ======================================================================
# DEFINIÇÃO DE CACHE MOVIDA PARA /etc/nginx/nginx.conf
# ======================================================================
# Mapa para definir o tempo de expiração do cache de assets
map $request_uri $cache_asset { map $request_uri $cache_asset {
~*\.(css|js|mjs|svg|gif|png|jpg|jpeg|ico|wasm|woff|woff2|ttf|otf)$ 1y; ~*\.(css|js|mjs|svg|gif|png|jpg|jpeg|ico|wasm|woff|woff2|ttf|otf)$ 1y;
default off; default off;
@ -40,92 +12,75 @@ map $request_uri $cacheable_session_request {
default 0; default 0;
} }
# UPSTREAMS map $cacheable_session_request $session_cache_zone {
1 nextcloud_session_cache;
default "";
}
upstream nextcloud_backend { upstream nextcloud_backend {
server 172.16.253.12; server 172.16.253.12;
# Mantém até 32 conexões ociosas abertas para o backend.
# Reduz a latência de TCP/IP para requisições frequentes.
#keepalive 32;
} }
upstream officeonline_backend { upstream officeonline_backend {
server 172.16.253.101; server 172.16.253.101;
} }
# BLOCO HTTP: Redirecionar para HTTPS
server { server {
listen 80; listen 80;
listen [::]:80; listen [::]:80;
server_name cloud.grupopralog.com.br; server_name cloud.grupopralog.com.br;
# Aplica o rate limiting a todo o tráfego HTTP.
limit_req zone=global_limit burst=20 nodelay;
# Responde ao desafio do Let's Encrypt
location /.well-known/acme-challenge/ { location /.well-known/acme-challenge/ {
root /var/www/html; root /var/www/html;
} }
# Redireciona todo o resto para HTTPS
location / { location / {
return 301 https://$host$request_uri; return 301 https://$host$request_uri;
} }
} }
# BLOCO HTTPS: Servidor Principal Otimizado
server { server {
listen 443 ssl http2; listen 443 ssl http2;
listen [::]:443 ssl http2; listen [::]:443 ssl http2;
server_name cloud.grupopralog.com.br; server_name cloud.grupopralog.com.br;
# --- Configurações Gerais ---
client_max_body_size 10G; client_max_body_size 10G;
access_log /var/log/nginx/cloud.grupopralog.com.br.access.log detailed_proxy; access_log /var/log/nginx/cloud.grupopralog.com.br.access.log detailed_proxy;
error_log /var/log/nginx/cloud.grupopralog.com.br.error.log warn; error_log /var/log/nginx/cloud.grupopralog.com.br.error.log warn;
access_log /var/log/nginx/cloud.grupopralog.com.br.bad-bot.log suspicious_bot if=$is_bad_bot; access_log /var/log/nginx/cloud.grupopralog.com.br.bad-bot.log suspicious_bot if=$is_bad_bot;
# --- Módulo de Segurança Global (definido em nginx.conf) ---
# Bloqueia bots e acesso a URIs suspeitas de forma centralizada.
if ($block_request) { if ($block_request) {
return 404; # Retornar 404 é mais discreto que 403 return 404;
} }
# --- Aplica o Rate Limiting (zona definida em nginx.conf) ---
limit_req zone=global_limit burst=100 nodelay; limit_req zone=global_limit burst=100 nodelay;
# --- Parâmetros de SSL/TLS (Ciphers atualizados conforme best practices) ---
ssl_certificate /etc/letsencrypt/live/cloud.grupopralog.com.br/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/cloud.grupopralog.com.br/privkey.pem; # managed by Certbot
ssl_protocols TLSv1.3 TLSv1.2;
ssl_ciphers 'TLS_AES_128_GCM_SHA256:TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305';
ssl_prefer_server_ciphers on;
ssl_ecdh_curve X25519:secp256r1:secp384r1;
# ssl_session_cache é definido globalmente em nginx.conf
ssl_session_timeout 1d;
ssl_dhparam /etc/nginx/dhparam.pem;
ssl_session_tickets off;
# OCSP Stapling
ssl_stapling on;
ssl_stapling_verify on;
ssl_trusted_certificate /etc/letsencrypt/live/cloud.grupopralog.com.br/fullchain.pem;
resolver 8.8.8.8 8.8.4.4 valid=300s;
resolver_timeout 5s;
# --- Cabeçalhos de Segurança Otimizados ---
add_header Strict-Transport-Security "max-age=63072000; includeSubDomains; preload" always; add_header Strict-Transport-Security "max-age=63072000; includeSubDomains; preload" always;
add_header X-Content-Type-Options "nosniff" always; add_header X-Content-Type-Options "nosniff" always;
add_header X-Frame-Options "SAMEORIGIN" always; add_header X-Frame-Options "SAMEORIGIN" always;
add_header Referrer-Policy "no-referrer" always; add_header Referrer-Policy "no-referrer" always;
#add_header Permissions-Policy "geolocation=(), midi=(), sync-xhr='self', microphone=(), camera=(), magnetometer=(), gyroscope=(), fullscreen=(), payment=()" always;
#add_header Content-Security-Policy "default-src 'none'; base-uri 'none'; manifest-src 'self'; script-src 'nonce-hM7OrLSVwumFk18lv8kzCmeGt8EDVd/0GWKxgzqi5U' 'strict-dynamic'; style-src 'self' 'unsafe-inline'; img-src 'self' data: blob: https://srvoffice001.itguys.com.br; font-src 'self' data:; connect-src 'self'; media-src 'self' data:; frame-src 'self' blob: https://srvoffice001.itguys.com.br; frame-ancestors 'self' https://srvoffice001.itguys.com.br; form-action 'self' https://srvoffice001.itguys.com.br;" always;
proxy_hide_header "X-Content-Type-Options";
proxy_hide_header "X-Frame-Options"; # Esconde header do backend para não duplicar
proxy_hide_header "Feature-Policy";
proxy_hide_header "Content-Security-Policy"; # Garante que nosso CSP seja o único aplicado.
# --- Bloco de Compressão --- proxy_hide_header "X-Content-Type-Options";
proxy_hide_header "X-Frame-Options";
proxy_hide_header "Feature-Policy";
proxy_hide_header "Content-Security-Policy";
ssl_certificate /etc/letsencrypt/live/cloud.grupopralog.com.br/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/cloud.grupopralog.com.br/privkey.pem;
ssl_protocols TLSv1.3 TLSv1.2;
ssl_ciphers 'TLS_AES_128_GCM_SHA256:TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY_1305_SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305';
ssl_prefer_server_ciphers on;
ssl_ecdh_curve X25519:secp256r1:secp384r1;
ssl_dhparam /etc/nginx/dhparam.pem;
ssl_session_timeout 1d;
ssl_session_tickets off;
ssl_stapling on;
ssl_stapling_verify on;
ssl_trusted_certificate /etc/letsencrypt/live/cloud.grupopralog.com.br/fullchain.pem;
resolver 127.0.0.1 valid=300s;
resolver_timeout 5s;
brotli on; brotli on;
brotli_comp_level 11; brotli_comp_level 6;
brotli_min_length 256; brotli_min_length 256;
brotli_types application/atom+xml application/javascript application/json application/rss+xml application/vnd.ms-fontobject application/x-font-opentype application/x-font-truetype application/x-font-ttf application/x-javascript application/xhtml+xml application/xml font/eot font/opentype font/otf font/truetype image/svg+xml image/x-icon text/css text/javascript text/plain text/xml; brotli_types application/atom+xml application/javascript application/json application/rss+xml application/vnd.ms-fontobject application/x-font-opentype application/x-font-truetype application/x-font-ttf application/x-javascript application/xhtml+xml application/xml font/eot font/opentype font/otf font/truetype image/svg+xml image/x-icon text/css text/javascript text/plain text/xml;
gzip on; gzip on;
@ -135,212 +90,59 @@ server {
gzip_min_length 256; gzip_min_length 256;
gzip_types application/atom+xml application/javascript application/json application/rss+xml application/vnd.ms-fontobject application/x-font-opentype application/x-font-truetype application/x-font-ttf application/x-javascript application/xhtml+xml application/xml font/eot font/opentype font/otf font/truetype image/svg+xml image/x-icon text/css text/javascript text/plain text/xml; gzip_types application/atom+xml application/javascript application/json application/rss+xml application/vnd.ms-fontobject application/x-font-opentype application/x-font-truetype application/x-font-ttf application/x-javascript application/xhtml+xml application/xml font/eot font/opentype font/otf font/truetype image/svg+xml image/x-icon text/css text/javascript text/plain text/xml;
# --- Rotas Específicas Nextcloud ---
location = /.well-known/carddav { return 301 /remote.php/dav; } location = /.well-known/carddav { return 301 /remote.php/dav; }
location = /.well-known/caldav { return 301 /remote.php/dav; } location = /.well-known/caldav { return 301 /remote.php/dav; }
# --- Bloco do Office Online ---
location ~ ^/(m|x|we|o|p|wv|op|wd|rtc|rtc2|layouts|view)/ { location ~ ^/(m|x|we|o|p|wv|op|wd|rtc|rtc2|layouts|view)/ {
brotli on;
gzip on;
expires $cache_asset;
proxy_pass http://officeonline_backend; proxy_pass http://officeonline_backend;
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' "$scheme://$http_host";
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS, HEAD';
add_header 'Access-Control-Allow-Headers' 'Authorization, Content-Type, Accept, Origin, User-Agent, DNT, Cache-Control, X-Mx-ReqToken, Keep-Alive, X-Requested-With, If-Modified-Since, X-UserType';
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Max-Age' 1728000;
return 204;
}
add_header 'Access-Control-Allow-Origin' "$scheme://$http_host" always;
add_header 'Access-Control-Allow-Credentials' 'true' always;
sub_filter 'srvoffice001.itguys.com.br' 'cloud.grupopralog.com.br';
sub_filter_once off;
sub_filter_types text/css text/javascript application/javascript application/json;
proxy_set_header Host "srvoffice001.itguys.com.br"; proxy_set_header Host "srvoffice001.itguys.com.br";
proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Host $host; proxy_set_header X-Forwarded-Host $host;
proxy_set_header Accept-Encoding "";
proxy_http_version 1.1; proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade; proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade"; proxy_set_header Connection "upgrade";
proxy_set_header Accept-Encoding "";
sub_filter 'srvoffice001.itguys.com.br' 'cloud.grupopralog.com.br';
sub_filter_once off;
sub_filter_types text/css text/javascript application/javascript application/json;
if ($request_method = 'OPTIONS') {
more_set_headers 'Access-Control-Allow-Origin: "$scheme://$http_host"';
more_set_headers 'Access-Control-Allow-Methods: GET, POST, OPTIONS, HEAD';
more_set_headers 'Access-Control-Allow-Headers: Authorization, Content-Type, Accept, Origin, User-Agent, DNT, Cache-Control, X-Mx-ReqToken, Keep-Alive, X-Requested-With, If-Modified-Since, X-UserType';
more_set_headers 'Access-Control-Allow-Credentials: true';
more_set_headers 'Access-Control-Max-Age: 1728000';
return 204;
} }
# --- Blocos de Cache --- more_set_headers 'Access-Control-Allow-Origin: "$scheme://$http_host"';
location /avatar/ { more_set_headers 'Access-Control-Allow-Credentials: true';
}
location ~* \.(?:css|js|mjs|svg|gif|png|jpg|jpeg|ico|wasm|woff|woff2|ttf|otf|map)$ {
proxy_pass http://nextcloud_backend; proxy_pass http://nextcloud_backend;
proxy_set_header Host $host; proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Forwarded-Proto $scheme;
proxy_cache nextcloud_cache;
proxy_cache_valid 200 302 1d;
proxy_cache_valid any 1m;
proxy_hide_header "Cache-Control";
proxy_hide_header "Expires";
proxy_hide_header "Pragma";
add_header Cache-Control "public, max-age=31536000, immutable";
add_header X-Proxy-Cache $upstream_cache_status;
}
location /apps/theming/image/ {
proxy_pass http://nextcloud_backend;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_cache nextcloud_cache;
proxy_cache_valid 200 1d;
proxy_cache_valid any 1m;
add_header Cache-Control "public, max-age=86400";
add_header X-Proxy-Cache $upstream_cache_status;
}
location ~ ^/apps/theming/.*(\.(svg|png|jpg|gif|css|js|woff2|ttf|ico))$ {
proxy_pass http://nextcloud_backend;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
# Aplicação do Cache Agressivo (1 Dia)
proxy_cache nextcloud_cache;
proxy_cache_valid 200 1d;
proxy_cache_valid any 1m;
# Headers para instruir o browser a manter o cache
add_header Cache-Control "public, max-age=86400";
add_header X-Proxy-Cache $upstream_cache_status;
# Usar expires para garantir que o NGINX envie o header "Expires" (boa prática)
expires 1d;
}
# Configuração Padrão para o restante do /apps/theming/ (sem cache longo)
# Isso garante que a lógica de backend ou arquivos que não são estáticos não sejam cacheados.
location /apps/theming/ {
proxy_pass http://nextcloud_backend;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
location ~* \.(js|css|svg|png|jpg|gif|woff2|ttf|ico)$ {
proxy_pass http://nextcloud_backend;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
# ------------------ Cache (30 Dias) ------------------
proxy_cache nextcloud_cache; proxy_cache nextcloud_cache;
proxy_cache_valid 200 30d; proxy_cache_valid 200 30d;
proxy_cache_valid any 1m; proxy_cache_valid any 1m;
add_header Cache-Control "public, max-age=2592000"; # 30 dias more_set_headers 'Cache-Control: public, max-age=31536000, immutable';
add_header X-Proxy-Cache $upstream_cache_status; more_set_headers 'X-Proxy-Cache: $upstream_cache_status';
expires 30d;
# ------------------ Compactação Brotli e Gzip ------------------ expires 1y;
# 1. Tenta servir o arquivo Brotli (.br) pré-comprimido, se o browser suportar.
brotli_static on;
# 2. Tenta servir o arquivo Gzip (.gz) pré-comprimido, se não encontrar o .br.
gzip_static on;
# Nota: Se o NGINX não encontrar arquivos pré-comprimidos (.br ou .gz),
# ele fará o proxy para o backend, que deve comprimir dinamicamente (se configurado).
}
location ~ \.(css|js|mjs|svg|gif|png|jpg|jpeg|ico|wasm|woff|woff2|ttf|otf|map)$ {
proxy_pass http://nextcloud_backend;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_cache nextcloud_cache;
proxy_cache_valid 200 302 1d;
proxy_cache_valid any 1m;
proxy_hide_header "Cache-Control"; proxy_hide_header "Cache-Control";
proxy_hide_header "Expires"; proxy_hide_header "Expires";
proxy_hide_header "Pragma"; proxy_hide_header "Pragma";
add_header Cache-Control "public, max-age=31536000, immutable"; brotli_static on;
add_header X-Proxy-Cache $upstream_cache_status; gzip_static on;
} }
location = /ocs/v2.php/apps/recommendations/api/v1/recommendations { location = /ocs/v2.php/apps/recommendations/api/v1/recommendations {
# --- Cache de Sessão Específico ---
# A chave DEVE incluir a sessão para ser única por usuário.
proxy_cache_key "$scheme$request_method$host$request_uri$is_args$args$cookie_nc_session_id";
proxy_cache nextcloud_session_cache; # Reutiliza a mesma zona de cache de sessão
# Tempo de cache específico para esta rota: 1 dia
proxy_cache_valid 200 1d;
proxy_cache_revalidate on;
proxy_cache_use_stale error timeout http_500 http_502 http_503 http_504;
# Header de depuração para facilitar o teste
add_header X-API-Rec-Cache $upstream_cache_status;
# --- Configurações de Proxy Padrão (necessárias para a comunicação) ---
proxy_pass http://nextcloud_backend;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Connection "";
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Requested-With $http_x_requested_with;
proxy_http_version 1.1;
proxy_buffering on; # Respostas de API são pequenas, buffering é eficiente aqui.
}
# --- Micro-caching para a API de listagem de pastas (Group Folders) ---
# Aplica um cache de apenas 3 segundos para a API que monta a árvore de diretórios.
# Isso protege o backend contra múltiplas requisições simultâneas para a mesma pasta,
# que é comum em group folders.
location = /apps/files/api/v1/folder-tree {
# A chave de cache DEVE incluir o cookie de sessão para evitar vazamento de dados.
proxy_cache_key "$scheme$request_method$host$request_uri$is_args$args$cookie_nc_session_id";
proxy_cache foldertree_cache;
proxy_cache_valid 200 3s; # Cache válido por apenas 3 segundos.
proxy_cache_lock on; # Evita que múltiplas requisições gerem o mesmo cache.
proxy_cache_use_stale error timeout http_500 http_502 http_503 http_504;
# Adiciona um header para depuração, para sabermos se o cache foi HIT ou MISS.
add_header X-FolderTree-Cache $upstream_cache_status;
# Configurações de proxy (copiadas do seu location /)
proxy_pass http://nextcloud_backend;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_http_version 1.1;
proxy_set_header Connection "";
proxy_buffering on; # Buffering é bom para pequenas respostas de API
}
location ~ ^/(ocs/v[12].php/cloud/users|ocs/v[12].php/privatedata/get|ocs/v2.php/apps/notifications/api/v2/notifications|ocs/v[12].php/cloud/apps|ocs/v[12].php/cloud/user|ocs/v[12].php/privatedata/get/userinfo) {
# Usar a mesma configuração de cache
proxy_cache nextcloud_cache;
# Usar a mesma chave segura: host + URI + ID da Sessão
proxy_cache_key "$host$request_uri|$cookie_nc_session_id";
# Cache muito curto (5 segundo) para evitar vazamento e garantir frescor
proxy_cache_valid 200 5s;
# Tratar erros e timeouts
proxy_cache_use_stale error timeout http_500 http_502 http_503 http_504;
# Header para depuração
add_header X-APIMicroCache-Status $upstream_cache_status;
# Configurações de proxy
proxy_pass http://nextcloud_backend; proxy_pass http://nextcloud_backend;
proxy_set_header Host $host; proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Real-IP $remote_addr;
@ -349,13 +151,56 @@ server {
proxy_http_version 1.1; proxy_http_version 1.1;
proxy_set_header Connection ""; proxy_set_header Connection "";
proxy_buffering on; proxy_buffering on;
proxy_cache nextcloud_session_cache;
proxy_cache_key "$scheme$request_method$host$request_uri$is_args$args$cookie_nc_session_id";
proxy_cache_valid 200 1d;
proxy_cache_revalidate on;
proxy_cache_use_stale error timeout http_500 http_502 http_503 http_504;
more_set_headers 'X-API-Rec-Cache: $upstream_cache_status';
} }
# --- Rota Principal da Aplicação Nextcloud --- location = /apps/files/api/v1/folder-tree {
location / { proxy_pass http://nextcloud_backend;
# --- CORREÇÃO: Lógica de Cache de Sessão --- proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_http_version 1.1;
proxy_set_header Connection "";
proxy_buffering on;
proxy_cache foldertree_cache;
proxy_cache_key "$scheme$request_method$host$request_uri$is_args$args$cookie_nc_session_id";
proxy_cache_valid 200 3s;
proxy_cache_lock on;
proxy_cache_use_stale error timeout http_500 http_502 http_503 http_504;
more_set_headers 'X-FolderTree-Cache: $upstream_cache_status';
}
# 1. (MOVIDO) As diretivas de cache são definidas aqui, no contexto do location. location ~ ^/(ocs/v[12].php/cloud/users|ocs/v[12].php/privatedata/get|ocs/v2.php/apps/notifications/api/v2/notifications|ocs/v[12].php/cloud/apps|ocs/v[12].php/cloud/user|ocs/v[12].php/privatedata/get/userinfo) {
proxy_pass http://nextcloud_backend;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_http_version 1.1;
proxy_set_header Connection "";
proxy_buffering on;
proxy_cache nextcloud_cache;
proxy_cache_key "$host$request_uri|$cookie_nc_session_id";
proxy_cache_valid 200 5s;
proxy_cache_use_stale error timeout http_500 http_502 http_503 http_504;
more_set_headers 'X-APIMicroCache-Status: $upstream_cache_status';
}
location / {
proxy_pass http://nextcloud_backend;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Host $host;
proxy_cache $session_cache_zone;
proxy_cache_key "$scheme$request_method$host$request_uri$is_args$args$cookie_nc_session_id"; proxy_cache_key "$scheme$request_method$host$request_uri$is_args$args$cookie_nc_session_id";
proxy_cache_valid 200 5m; proxy_cache_valid 200 5m;
proxy_cache_revalidate on; proxy_cache_revalidate on;
@ -363,33 +208,10 @@ server {
proxy_cache_bypass $http_cache_control; proxy_cache_bypass $http_cache_control;
proxy_no_cache $http_cache_control; proxy_no_cache $http_cache_control;
# 2. (CORRIGIDO) A variável que define a zona de cache é inicializada como vazia. more_set_headers 'X-Session-Cache: $upstream_cache_status';
set $session_cache_zone "";
# 3. (CORRIGIDO) O 'if' agora apenas define o nome da zona de cache na variável.
if ($cacheable_session_request) {
set $session_cache_zone "nextcloud_session_cache";
}
# 4. (CORRIGIDO) A diretiva 'proxy_cache' usa a variável.
# Se a variável estiver vazia, o cache é desativado para a requisição.
proxy_cache $session_cache_zone;
# Header de depuração continua funcionando normalmente.
add_header X-Session-Cache $upstream_cache_status;
# --- Configurações de Proxy Padrão ---
proxy_pass http://nextcloud_backend;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Connection "";
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Port $server_port;
proxy_set_header User-Agent $http_user_agent;
proxy_set_header X-Requested-With $http_x_requested_with;
proxy_http_version 1.1; proxy_http_version 1.1;
proxy_set_header Connection "";
proxy_connect_timeout 60s; proxy_connect_timeout 60s;
proxy_read_timeout 1200s; proxy_read_timeout 1200s;
proxy_send_timeout 1200s; proxy_send_timeout 1200s;