Skip to content

Commit 80a54c1

Browse files
feat: enable nginx content caching for static files
1 parent 61c1267 commit 80a54c1

File tree

2 files changed

+43
-2
lines changed

2 files changed

+43
-2
lines changed

k8s/app.yaml

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ metadata:
6363
annotations:
6464
kubernetes.io/ingress.class: nginx
6565
certmanager.k8s.io/cluster-issuer: letsencrypt-prod
66-
nginx.ingress.kubernetes.io/proxy-body-size: "0"
6766
spec:
6867
tls:
6968
- hosts:
@@ -85,3 +84,42 @@ spec:
8584
backend:
8685
serviceName: chime
8786
servicePort: 80
87+
88+
---
89+
90+
apiVersion: extensions/v1beta1
91+
kind: Ingress
92+
metadata:
93+
name: chime-static
94+
namespace: chime
95+
labels:
96+
app: chime
97+
annotations:
98+
nginx.ingress.kubernetes.io/proxy-body-size: "0"
99+
nginx.ingress.kubernetes.io/proxy-buffering: "on" # Important!
100+
nginx.ingress.kubernetes.io/configuration-snippet: |
101+
proxy_cache static-cache;
102+
proxy_cache_valid 404 1m;
103+
proxy_cache_valid 200 10m;
104+
proxy_cache_use_stale error timeout updating http_404 http_500 http_502 http_503 http_504;
105+
proxy_cache_bypass $http_x_purge;
106+
proxy_cache_key $proxy_upstream_name$request_uri;
107+
proxy_cache_lock on;
108+
proxy_cache_use_stale updating;
109+
add_header X-Cache-Status $upstream_cache_status;
110+
spec:
111+
rules:
112+
- host: penn-chime.phl.io
113+
http:
114+
paths:
115+
- path: /static/
116+
backend:
117+
serviceName: chime
118+
servicePort: 80
119+
- host: lke.penn-chime.phl.io
120+
http:
121+
paths:
122+
- path: /static/
123+
backend:
124+
serviceName: chime
125+
servicePort: 80

k8s/infra/ingress-nginx.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ metadata:
1616
labels:
1717
app.kubernetes.io/name: ingress-nginx
1818
app.kubernetes.io/part-of: ingress-nginx
19+
data:
20+
http-snippet: |
21+
proxy_cache_path /tmp/nginx-cache levels=1:2 keys_zone=static-cache:2m max_size=100m inactive=7d use_temp_path=off;
1922
2023
---
2124
kind: ConfigMap
@@ -196,7 +199,7 @@ metadata:
196199
app.kubernetes.io/name: ingress-nginx
197200
app.kubernetes.io/part-of: ingress-nginx
198201
spec:
199-
replicas: 5
202+
replicas: 1
200203
selector:
201204
matchLabels:
202205
app.kubernetes.io/name: ingress-nginx

0 commit comments

Comments
 (0)