【发布时间】:2020-02-20 22:38:50
【问题描述】:
本地缓存工作正常,但是尝试通过 Azure Blob 存储缓存文件服务器不起作用。
每个请求的签名都会更改,并且不会返回缓存标头。 我认为是因为最后这个签名?有人知道如何超越吗?
https://accountname.blob.core.windows.net/static/assets/js/jquery331.min.js?se=2020-02-10T15%3A06%3A35Z&sp=r&sv=2019-09-28&sr=b&sig=<Signature>
下面是我的 nginx 配置。它主要基于这个=https://serversforhackers.com/c/nginx-caching
upstream app {
server web:8000;
}
proxy_cache_path ./cache keys_zone=one:10m loader_threshold=300 loader_files=200;
proxy_cache_key "$scheme$request_method$host$request_uri";
# Expires map
map $sent_http_content_type $expires {
default off;
text/css max;
application/javascript max;
~image/ max;
}
server {
include mime.types;
listen 80;
listen [::]:80;
root /usr/src/application/;
index /usr/src/application/main/;
gzip on;
gzip_comp_level 2;
gzip_http_version 1.0;
gzip_proxied any;
gzip_min_length 1100;
gzip_buffers 16 8k;
gzip_types text/plain text/html text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript script text/script;
gzip_disable "MSIE [1-6].(?!.*SV1)";
gzip_vary on;
location / {
proxy_pass http://app;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_redirect off;
}
location /staticfiles/ {
proxy_cache one;
proxy_buffering on;
add_header X-Proxy-Cache $upstream_cache_status;
proxy_http_version 1.1;
proxy_set_header Connection "";
proxy_set_header Authorization '';
proxy_set_header Host https://accountname.blob.core.windows.net/static;
proxy_pass https://accountname.blob.core.windows.net;
}
location /media/ {
proxy_http_version 1.1;
proxy_set_header Connection "";
proxy_set_header Authorization '';
proxy_set_header Host https://accountname.blob.core.windows.net/media;
proxy_pass https://accountname.blob.core.windows.net;
}
# cache.appcache, your document html and data
location ~* \.(?:manifest|appcache|html?|xml|json)$ {
expires -1;
}
# Feed
location ~* \.(?:rss|atom)$ {
expires 1h;
add_header Cache-Control "public";
}
# Media: images, icons, video, audio, HTC
location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc)$ {
expires 1M;
access_log off;
add_header Cache-Control "public";
}
# CSS and Javascript
location ~* \.(?:css|js)$ {
expires 1y;
access_log off;
add_header Cache-Control "public";
}
location /media/ {
alias /usr/src/application/main/media;
}
proxy_connect_timeout 300s;
proxy_read_timeout 300s;
proxy_next_upstream error timeout http_502;
location /index/ {
alias /usr/src/application/main/;
}
}
【问题讨论】:
-
你也是用CDN还是只用nginx?
-
Nginx 和 Azure 存储 Blob。是否必须启用 CDN?
-
不,我只是想知道缓存是否会由 cdn 处理。
-
我创建了一个 CDN,添加了端点,但仍然是同样的问题。唯一改变的是
https://accountname.azureedge.net/static/assets/js/jquery331.min.js?se=2020-02-10T15%3A06%3A35Z&sp=r&sv=2019-09-28&sr=b&sig=<Signature>
标签: azure nginx caching azure-storage azure-blob-storage