'Serve static assets with an efficient cache policy via nginx

I'm trying to increase the performance of my site. I got about ~83 right now accordingly Google Page Speed Insight. While it's not the worst, it's not great either. One of the issues is caching, I need to leverage caching and increase the long life of my static assets.

enter image description here

My site is behind Cloudflare. Do I need to apply any settings there?



Solution 1:[1]

add these lines to : /etc/nginx/sites-available/default

# Media: images, icons, video, audio, HTC
location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|mp3|wav|ogg|ogv|webm|htc|woff2|woff)$ {
    expires 1M;
    access_log off;
    add_header Cache-Control "public";
}

and service nginx reload

Result

enter image description here

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 code-8