Configured proxy_cache_path for keys_zone=static-cache via ConfigMap. I will check that this is exactly applied in the configuration. It does:
$ kubectl -n ingress-nginx exec -it pod/$POD_IC_NAME -- cat /etc/nginx/nginx.conf | grep proxy_cache_path
proxy_cache_path /tmp/nginx_cache levels=1:2 keys_zone=static-cache:10m max_size=10g inactive=60m use_temp_path=off;
proxy_cache_path /tmp/nginx/nginx-cache-auth levels=1:2 keys_zone=auth_cache:10m max_size=128m inactive=30m use_temp_path=off;
Now I'm configuring Ingress. I get a helm template like this:
{{ if .Values.createIngress }}
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: ntp-integration-bff-2-{{ .Release.Name }}
annotations:
{{ if .Values.http2Enable }}
nginx.ingress.kubernetes.io/enable-http2: "true"
{{ end }}
{{ if and .Values.httpCache .Values.services.ntp.integrationBff.httpCache }}
nginx.ingress.kubernetes.io/server-snippet: |
location ~* ^/api/v2/ {
proxy_buffering on;
proxy_cache static-cache;
proxy_cache_valid 200 30m;
proxy_cache_methods GET;
proxy_cache_key "$scheme$request_uri";
proxy_ignore_headers "Cache-Control" "Expires" "Set-Cookie" "Vary";
proxy_hide_header Cache-Control;
proxy_cache_bypass off;
proxy_no_cache off;
proxy_cache_lock on;
proxy_cache_use_stale updating error timeout http_500 http_502 http_503 http_504;
proxy_cache_convert_head off;
proxy_cache_min_uses 1;
proxy_cache_background_update on;
add_header X-Cache-Status $upstream_cache_status;
# Директивы для проксирования заголовков
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_pass http://ntp-integration-bff-{{ .Release.Name }}.{{ .Release.Namespace }}.svc.cluster.local:8000;
}
{{ end }}
spec:
ingressClassName: nginx
{{ if .Values.tls.enable }}
tls:
- hosts:
- {{ .Values.ingress.api.publicDomain2 }}
secretName: platform-tls-secret
{{ end }}
rules:
- host: {{ .Values.ingress.api.publicDomain2 }}
http:
paths:
- path: /api/v3
pathType: Prefix
backend:
service:
name: ntp-integration-bff-{{ .Release.Name }}
port:
number: 8000
{{ end }}
I'm getting this configuration :
location ~* ^/api/v2/ {
proxy_buffering on;
proxy_cache static-cache;
proxy_cache_valid 200 30m;
proxy_cache_methods GET;
proxy_cache_key "$scheme$request_uri";
proxy_ignore_headers "Cache-Control" "Expires" "Set-Cookie" "Vary";
proxy_hide_header Cache-Control;
proxy_cache_bypass off;
proxy_no_cache off;
proxy_cache_lock on;
proxy_cache_use_stale updating error timeout http_500 http_502 http_503 http_504;
proxy_cache_convert_head off;
proxy_cache_min_uses 1;
proxy_cache_background_update on;
add_header X-Cache-Status $upstream_cache_status;
# Директивы для проксирования заголовков
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_pass :8000;
}
But in the browser I see that all requests are returned with x-cache-status: BYPASS
REQUEST = /api/v2/query/ru/system-banner
Request Headers
GET /api/v2/query/ru/system-banner HTTP/1.1
Accept: application/json, text/plain, */*
Accept-Encoding: gzip, deflate
Accept-Language: ru-RU,ru;q=0.9,en-US;q=0.8,en;q=0.7,id;q=0.6,zh-TW;q=0.5,zh;q=0.4,fr;q=0.3,bg;q=0.2
Authorization: Bearer eyJhbGciOiJIUzUxMiJ9.eyJqdGkiOiJjOTlhMzc0Yi02YjliLTQzZTQtYjYxNy1hYmJkZDNhMjkyNjciLCJzdWIiOiJGQU1JTElZQV9JLk8iLCJleHAiOjE3Mzk1NDAxMjQsImlhdCI6MTczODY3NjEyNH07OS0yDQtQMjUYXnCDFlJtVoSSjuGpbhh_167geQ6YtuPHIotI507X-pFl2w3eIIzGZkfzmbEBjMe8oALVZ9Q
Connection: keep-alive
Cookie: username=...; backend=...; rt_a=eyJhbGciOiJIUzI1NiIsIn....; Authorization=Bearer%20eyJhbGciOiJIUz...; rt_r=qjkWLS8xkfcw...
Host: dev190.local
Referer: /gp-frontend-gp-main/
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36
Response Headers
HTTP/1.1 200 OK
Date: Tue, 04 Feb 2025 13:53:51 GMT
Content-Type: application/json; charset=utf-8
Content-Length: 447
Connection: keep-alive
X-Cache-Status: BYPASS
I don't understand what else can be configured to make these Nginx requests cached? According to my logic caching should already work.