如何修复利用浏览器缓存 nginx?

how to fix Leverage browser caching nginx?

我上网,设置了所有可能的缓存设置,但都一样 google 页面加速见解的末尾写道,我没有这些文件的缓存如何解决这个问题?

我的缓存设置"nano /etc/nginx/nginx.conf"

 proxy_temp_path /var/nginx/proxy_temp;
 add_header X-Cache-Status $upstream_cache_status;
 proxy_cache_path /tmp/nginx/cache levels=1:2 keys_zone=one:100m;
 proxy_cache one;
 proxy_cache_valid any 30d;
 proxy_cache_key $scheme$proxy_host$request_uri$cookie_US;

我的服务器配置 "nano /etc/nginx/sites-enabled/theband"

location ~* ^(?!/media).*.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc)$ {
    expires 365d;
    add_header Cache-Control "public, must-revalidate, proxy-revalidate";
    access_log off;
}
location ~* ^(?!/static).*.(?:css|js|html)$ {
    expires 365d;
    add_header Cache-Control "public, must-revalidate, proxy-revalidate";
    access_log off;
}

location / {
    proxy_set_header X-Real-IP $remote_addr;

    proxy_cache one;
    proxy_cache_min_uses 1;
    proxy_cache_use_stale error timeout;

"expires 35d;" 此行需要删除,从您定义它的位置创建文件存储。

从这里开始:

   location ~* ^(?!/media).*.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc)$ {
        root /tmp/nginx/trash/trash_media;
        expires 35d; # REMOVE THISSSSSSSS
        add_header Pragma public;
        add_header Cache-Control "public, must-revalidate, proxy-revalidate";
        access_log off;
    }

到这里:

server {

    listen   80;
    server_name myip;
    expires 35d;
    client_max_body_size 4G;

and it will work, although in all absolutely examples, you do not need to put storage time there !!!!!!

也不要忘记允许从网络接受数据并从本地存储写入和读取数据

sudo chown www-data /tmp/nginx/proxy_temp
sudo chmod 700 /tmp/nginx/proxy_temp
sudo chown www-data /tmp/nginx/cache
sudo chmod 700 /tmp/nginx/cache
sudo chown www-data /tmp/nginx/cache2
sudo chmod 700 /tmp/nginx/cache2

我通过从服务器块移动过期解决了这个问题

server {
    expires 35d;
    ...
}

到父 http 块

http {
    expires 35d;
    ...
}

"Context: http, server, location, if in location" 表明它可以驻留在这些块中。不确定为什么我的不能在服务器或位置工作。 http://nginx.org/en/docs/http/ngx_http_headers_module.html?&_ga=2.49684582.1104146524.1536596059-1026560835.1535666041#expires