How to gzip file in nginx server

Posted By : Himanshu sharma | 05-Apr-2016

This blog is about improving your website performance in the browser.

 However,  compression  in it can also add considerable processing overhead which can negatively affect performance. NGINX performs compression before sending responses to clients, but does not “double compress” responses that are already compressed (for example, by a proxied server).

This decrease the size of file tranmitting from the server , hence makes your website render fast in browser

add this in /etc/nginx/nginx.conf file inside http {} to gzip on

 

 # Gzip Settings
        ##

        gzip on;
        gzip_disable "msie6";
         gzip_min_length    256;
         gzip_vary on;
         gzip_proxied any;
         gzip_comp_level 6;
         gzip_buffers 16 8k;
         gzip_http_version 1.1;
         gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;

and this also for caching the file

 

 server {

        location ~* \.(jpg|jpeg|png|gif|ico|css|js|woff|woff2)$ {

           access_log off;

           expires 7d;

           add_header Pragma public;

           add_header Cache-Control "public,must-revalidate, proxy-revalidate";

 

          }

        }

THANKS

About Author

Author Image
Himanshu sharma

Himanshu has marvelous coding skills. In Free time too he loves to do coding and sometimes play Cricket.

Request for Proposal

Name is required

Comment is required

Sending message..