10
我通過nginx的服務於單個頁面的JavaScript應用程序更換指紋文件服務器的時候,當我部署新的版本,我想迫使瀏覽器無效的JS緩存和請求過期在瀏覽器中緩存的資產/使用最新版本可用。通過nginx的
因此,舉例來說,當我更換了服務器的文件夾,命名爲my-app-8e8faf9.js
一個文件,一個叫my-app-eaea342.js
文件,我不希望瀏覽器拉離其緩存my-app-8e8faf9.js
了。但是當沒有可用的新版本時,我仍然希望他們從緩存中讀取資源。
如何通過nginx配置實現此目的?這是我現有的配置:
server {
listen 80;
server_name my.server.com;
root /u/apps/my_client_production/current;
index index.html;
# ~2 seconds is often enough for most folks to parse HTML/CSS and
# retrieve needed images/icons/frames, connections are cheap in
# nginx so increasing this is generally safe...
keepalive_timeout 10;
client_max_body_size 100M;
access_log /u/apps/my_client_production/shared/log/nginx.access.log;
error_log /u/apps/my_client_production/shared/log/nginx.error.log info;
location/{
try_files $uri $uri/ =404;
gzip_static on;
expires max;
add_header Cache-Control public;
}
# Error pages
error_page 500 502 503 504 /500.html;
}