我们正在使用运行 nginx 代理(缓存已关闭)的 VM 将主机重定向到正确的 CDN url。
我们遇到了代理显示与 CDN 上显示的内容不匹配的旧内容的问题。我们使用的 CDN 提供商是 Verizon(通过 Azure - Microsoft CDN by Verizon)。
当我们对源进行更新时,我们会自动向 CDN 发送清除请求。这些可以是手动和自动动态更新,也可以是单个 url 清除和通配符。似乎正在发生的事情是当我们及时收到 2 个清除请求时。第一个通过代理,但第二个没有。尽管在直接访问 CDN url 时两者都正确显示。
值得一提的是,这个问题只发生在大约 30%的时间里。
nginx 示例配置:
server {
resolver 8.8.8.8;
server_name <CUSTOM HOST>;
location / {
# Turn off all caching
proxy_no_cache 1;
proxy_cache_bypass 1;
proxy_redirect off;
expires -1;
proxy_cache off;
# Proxy settings
proxy_set_header X-Forwarded-Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_headers_hash_max_size 512;
proxy_headers_hash_bucket_size 128;
# Override cache headers to set 2min browser cache
proxy_hide_header Cache-Control;
add_header Cache-Control max-age=120;
proxy_pass "<CDN URL>request_uri";
}
}
nginx.conf:
user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;
events {
worker_connections 768;
# multi_accept on;
}
http {
sendfile off;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
##
# SSL Settings
##
ssl_protocols TLSv1.2 TLSv1.3;
ssl_prefer_server_ciphers on;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
gzip on;
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
下面是一个示例,其中 CDN 显示比代理更新的内容,我们有一个 Last-Modifed 不匹配:
我已经尝试通过 VPN 来查看代理命中的特定 POP 是否有任何内容,但所有 POP:s 都显示正确的内容。
出现错误时,从代理向 CDN 发送curl请求将导致相同的错误标头。
在我们执行清除后,几个请求直接通过源,直到 CDN 再次开始提供缓存版本。
大约 1 分钟后,我们收到了第一个 HIT。
我开始假设这可能与 Azure 和 Verizon 内部有关。所以我创建了一个托管在亚马逊上的完全相同的代理,但错误似乎很明显。nginx 中是否还有其他可能导致这种行为的东西?