简体   繁体   中英

Leverage browser caching - nginx with CDN

I'm testing my site with pingdom : https://tools.pingdom.com/#!/dCLQGc/https://stagingreport.daytwo.com

And getting a low grade in leverage browser caching: 在此处输入图片说明

All static files being served from an nginx server with the following configuration

server {
   listen 80;

    gzip on;
    gzip_vary on;
    gzip_types    text/plain application/javascript application/x-javascript text/javascript text/xml text/css;


    access_log  /var/log/nginx/access.log;
    error_log   /var/log/nginx/error.log;

    root /usr/share/nginx/html;
    index index.html index.htm;

    location / {
        if ($http_x_forwarded_proto = "http") {
            return 301 https://$host$request_uri;
        }

        try_files $uri $uri/ /index.html;
    }


}

Because I'm using google cloud CDN I didn't setup any caching configuration on server.

In order to get a higher performance score should I change something in the nginx configuration?

As per the caching details mentioned below, you might need to configure the nginx accordingly:

A response can be stored in Cloud CDN caches only if all of the following are true:

It was served by a backend service or backend bucket with Cloud CDN enabled.

It is a response to a GET request.

Its status code is 200, 203, 206, 300, 301, 302, 307, or 410.

It has either a Content-Length header or a Transfer-Encoding header.

It has a Cache-Control: public header.

It has a Cache-Control: s-maxage, Cache-Control: max-age, or Expires header.

It has a Content-Length, Content-Range, or Transfer-Encoding header.

Its size is less than or equal to the maximum size.

For backend buckets, you can satisfy these requirements by marking the object as shared publicly.

There are also checks that block caching of responses. A response is not cached if any of the following are true:

It has a Set-Cookie header.

It has a Vary header with a value other than Accept, Accept-Encoding, or Origin.

It has a Cache-Control: no-store, no-cache, or private directive.

The corresponding request had a Cache-Control: no-store directive.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM