我正在尝试弄清楚如何使用nginx代理缓存并应用一些特定规则。例如,当我托管Ghost或WordPress时,我不希望缓存管理部分。使用服务器片段,我尝试了很多不同的组合,但在管理员部分仍然存在缓存问题。
nginx.ingress.kubernetes.io/proxy-buffering: "on"
nginx.ingress.kubernetes.io/server-snippet: |-
proxy_ignore_headers X-Accel-Expires Expires Cache-Control;
proxy_ignore_headers Set-Cookie;
proxy_cache app_cache;
proxy_cache_lock on;
proxy_cache_valid any 30m;
add_header X-Cache-Status $upstream_cache_status;
我希望你能为(ghost | sinout)路径使用nginx代码片段,在管理区域时绕过缓存,但我丢失了proxy_pass上下文,导致502网关错误。 这是当前的Ingress配置,缓存每个页面,包括管理员路径:
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
annotations:
nginx.ingress.kubernetes.io/proxy-buffering: "on"
nginx.ingress.kubernetes.io/server-snippet: |-
proxy_cache my_blog_cache;
proxy_cache_lock on;
proxy_cache_valid any 30m;
add_header X-Cache-Status $upstream_cache_status;
proxy_ignore_headers X-Accel-Expires Expires Cache-Control;
name: my-blog
namespace: web
spec:
rules:
- host: blog.example.com
http:
paths:
- backend:
serviceName: ingress-541322b8660dbd2ceb1e8ff1813f0dd5
servicePort: 2368
path: /
tls:
- hosts:
- blog.example.com
secretName: my-blog-cert
status:
loadBalancer:
ingress:
- ip: 1.2.3.4
这是我尝试获取的nginx配置,但不兼容Ingress注释:
location / {
proxy_cache my_blog_cache;
proxy_cache_valid 200 30m;
proxy_cache_valid 404 1m;
proxy_pass http://ghost_upstream;
proxy_ignore_headers X-Accel-Expires Expires Cache-Control;
proxy_ignore_headers Set-Cookie;
proxy_hide_header Set-Cookie;
proxy_hide_header X-powered-by;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
expires 10m;
}
location /content/images {
alias /path/to/ghost/content/images;
access_log off;
expires max;
}
location /assets {
alias /path/to/ghost/content/themes/uno-master/assets;
access_log off;
expires max;
}
location /public {
alias /path/to/ghost/core/built/public;
access_log off;
expires max;
}
location /ghost/scripts {
alias /path/to/ghost/core/built/scripts;
access_log off;
expires max;
}
location ~ ^/(?:ghost|signout) {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
proxy_pass http://ghost_upstream;
add_header Cache-Control "no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0";
}
感谢您的帮助!