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
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
Himanshu sharma
Himanshu has marvelous coding skills. In Free time too he loves to do coding and sometimes play Cricket.