Enable gzip and leverage cache on nginx server.

Enable gzip and leverage cache on nginx server.
Facebooktwitterredditpinterestlinkedinmail

Enable gzip and leverage cache on nginx server

Enable gzip and leverage cache on nginx server. It will help to improve magento store speed and optimize content delivery by compressing content into gzip.

Login on server with root access and create the below mentioned file.

For gzip compression.

vi /etc/nginx/conf.d/gzip.conf

add the below mentioned code in file.

gzip         on;
gzip_disable "MSIE [1-6]\.(?!.*SV1)";
gzip_proxied any;
gzip_types   text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript image/x-icon image/bmp image/svg+xml;
gzip_vary    on;

For leverage cache.

Add the below mentioned code in server section in

location ~* \.(js|css|png|jpg|jpeg|gif|ico)(\?ver=[0-9.]+)?$ {
    expires 1y;
}

Example

server {
    listen       80;
    server_name  localhost;

    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;
    }

    location ~* \.(js|css|png|jpg|jpeg|gif|ico)(\?ver=[0-9.]+)?$ {
		expires 1y;
	}
    location ~*  \.(pdf)$ {
        expires 30d;
    }
}
Facebooktwitterredditpinterestlinkedinmail