Control Panel

Add Cache-Control-Header / Expire-Header in NGINX

Hi, I added both cache-control-header and expire-header to /etc/nginx/sites-enabled/* on the console (there was no server block in the main conf file). Still, both Pagespeed and GTMetrix say that browser caching is not leveraged. It is making my site considerably slower, please help!

These are the codes I used:

location ~* \.(js|css|png|jpg|jpeg|gif|svg|ico)$ {
expires 30d;
add_header Cache-Control “public, no-transform”;
}

location ~* .(jpg|jpeg|gif|png|svg)$ {
expires 365d;
}

location ~* \.(pdf|css|html|js|swf)$ {
expires 2d;
}

 

Related Articles