簡體   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