Nginx proxy_cache

时间:2017-05-25 19:23:40

标签: caching nginx

我试图让nginx作为缓存代理运行。服务器已启动并正常运行 - 除非它似乎没有正确缓存。

根据pingdom扫描:

The following cacheable resources have a short freshness lifetime. Specify
an expiration at least one week in the future for the following resources:

/layout/theme1/css/bootstrap-responsive.css
/layout/theme1/css/bootstrap.min.css
/layout/theme1/css/font-awesome.css
/layout/theme1/css/pages/dashboard.css
/layout/theme1/css/style.css
/layout/theme1/css/theme.css
/layout/theme1/img/logo.png
/layout/theme1/js/bootstrap.js
/layout/theme1/js/chart.min.js
/layout/theme1/js/excanvas.min.js
/layout/theme1/js/jquery.js

我的nginx proxy_cache设置如下:

代理缓存路径设置:

proxy_cache_path /var/cache/nginx/marketers.coop levels=1:2 keys_zone=marketers.coop:10m inactive=525600m max_size=5120m;

位置设置:

location / {
    proxy_pass      http://192.227.210.138:8080;
    proxy_cache cache;
    proxy_cache_valid 30d;
    proxy_cache_valid 404 30d;
    proxy_no_cache $no_cache;
    proxy_cache_bypass $no_cache;
    proxy_cache_bypass $cookie_session $http_x_update;

    location ~* ^.+\.(jpg|jpeg|gif|png|ico|svg|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|odt|ods|odp|odf|tar|wav|bmp|rtf|js|mp3|avi|mpeg|flv|html|htm)$ {
        proxy_pass      http://192.227.210.138:8080;
        proxy_cache    cache;
        proxy_cache_valid 30d;
        proxy_cache_valid 404 30d;
        root           /home/admin/web/marketers.coop/public_html;
        access_log     /var/log/apache2/domains/marketers.coop.log combined;
        access_log     /var/log/apache2/domains/marketers.coop.bytes bytes;
        expires        365d;
        try_files      $uri @fallback;
    }
}

可以看出,css和js都被设置为缓存,但365天的过期和30天的代理缓存都没有任何效果。我做错了什么?

0 个答案:

没有答案