繁体   English   中英

使用 Azure 存储 Blob 进行 Nginx 缓存

[英]Nginx caching with Azure Storage Blob

本地缓存工作正常,但是尝试通过 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/;
    }
}

所以我找到了导致查询字符串的原因。 我们正在使用 django 存储,因为变量 AZURE_URL_EXPIRATION_SECS 的选项是可能的,它附加一个查询字符串。 截至目前,缓存工作无需 CDN。 但是,令我惊讶的是 CDN 处于活动状态并且规则设置为忽略查询字符串时没有发生缓存。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM