大叔经验分享(74)nginx对静态文件加速

通过location配置

    location ~ \.html$ {
        add_header 'Cache-Control' 'no-cache';
    }
    location ~ \.(js|css|gif|jpg|jpeg|png|bmp|swf)$) {
        access_log off;
        expires 7d;
    }

在location内配置

    location ^~ /testpath {
        if ($uri ~ \.html$) {
                add_header 'Cache-Control' 'no-cache';
        }
        if ($uri ~ \.(js|css|gif|jpg|jpeg|png|bmp|swf)$) {
                access_log off;
                expires 7d;
        }
        ...
    }

 

posted @ 2019-07-03 15:41  匠人先生  阅读(677)  评论(0编辑  收藏  举报