我有这个入口配置,但所有 html 和 json 响应页面都不包含添加的标头:
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: {{ $app }}-ingress
labels:
app: {{ $app }}
chart: chart-{{ $app }}
app.kubernetes.io/managed-by: Helm
annotations:
meta.helm.sh/release-name: {{ $app }}
meta.helm.sh/release-namespace: {{ .Release.Namespace }}
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/proxy-body-size: "{{ $proxy_body_size }}"
nginx.ingress.kubernetes.io/proxy-read-timeout: "{{ $proxy_read_timeout }}"
nginx.ingress.kubernetes.io/proxy-connect-timeout: "{{ $proxy_connect_timeout }}"
nginx.ingress.kubernetes.io/proxy-send-timeout: "{{ $proxy_send_timeout }}"
nginx.ingress.kubernetes.io/proxy-buffer-size: "{{ $proxy_buffer_size }}"
nginx.ingress.kubernetes.io/rewrite-target: /$1
nginx.ingress.kubernetes.io/configuration-snippet : |
if ($request_uri ~* \.(html|json)) {
add_header Cache-Control "no-cache,no-store";
}
spec:
tls:
- hosts:
- {{ $alias }}
rules:
- host: {{ $alias }}
http:
paths:
- path: /(.*)
backend:
serviceName: {{ $app }}-service
servicePort: http-back
我只想禁用 html 和 json 内容响应的缓存控制。当我删除 if ($request_uri ~* .(html|json)) 条件时,所有响应都具有添加的标头。所以这意味着配置片段中的条件不正确。
你能帮忙吗?
我遇到了同样的问题,这样的事情对我有用:
if ($request_uri ~* \.(?:html|json)$) {
add_header Cache-Control "no-store,no-cache";
add_header Pragma "no-cache";
}
这对我有用:
if ($request_uri ~* \.(?:html|json)$) {
add_header Cache-Control "no-store, no-cache" always;
add_header Pragma "no-cache" always;
}
if ($request_uri ~*
\.(?:js|css|png|jpg|jpeg|gif|ico|svg|webp|woff|woff2|ttf)$) {
add_header Cache-Control "public, max-age=3600" always;
}