{"id":7158,"date":"2017-12-18T17:28:12","date_gmt":"2017-12-18T17:28:12","guid":{"rendered":"http:\/\/hostileblog.com\/?p=5708"},"modified":"2020-05-30T21:31:28","modified_gmt":"2020-05-31T01:31:28","slug":"nginx-gzip_static","status":"publish","type":"post","link":"https:\/\/www.carnaghan.com\/nginx-gzip_static\/","title":{"rendered":"Nginx gzip_static: What it does and how to use it?"},"content":{"rendered":"
<\/p>\n
Like other top\u00a0web servers, Nginx lets webmasters enable Gzip compression for their websites. It can compress scripts and stylesheets in a web page on the fly. The Gzip file’s size is significantly lower than the original file.\u00a0Nginx supports 9 Gzip compression levels.1 is the lowest and 9 is the highest. To gzip a file, Nginx will use invoke a function and the\u00a0function will use system resources during the file conversion process.\u00a0The function will take few milliseconds\u00a0to execute.<\/p>\n
Gzipping content improves the performance of the website<\/a>, but it increases the load on a web server. If you have got a popular site that receives tons of direct visitors, you can reduce the cost of hosting by compressing scripts.<\/p>\n As in real life, even a fraction of a second can make a huge difference on the Internet. According to renowned SEO experts, if e-commerce site’s loading speed increases by a second, the customers will ditch the site or may not make any purchase. Google, the world’s largest search engines consider page speed as one of its search engine ranking signals.<\/p>\n Gzip_static is a module which makes Nginx serve precompressed GZIP files instead of compressing files on the fly. Along with the FastCGI cache, GS is one of the top features of Nginx.<\/p>\n Step 1:<\/strong><\/p>\n Nginx will search for the Gzip files in the directory. If it doesn’t find one, the web server will covert CSS\/js files into Gzip. If you want to use the Gzip static module, the first thing you should do is create gzip versions of the static assets on your site (excluding images, and server-side code files). To do so, you can use the default Gzip tool in Linux OS i.e. Gunzip. For better compression and to save more bandwidth, you can use Google Brotli<\/a> or Zopfli<\/a> to\u00a0generate Gzip files.<\/p>\n Step2: (Very important)<\/strong><\/p>\n Make sure that Nginx has the permission to access the newly generated Gzip file. If you don’t assign this permission to Nginx, won’t send the Gzipped file to the client browser and search bots will report HTTP 500 error in the webmaster consoles.<\/p>\n Modify the below command’s last 5 words as per your requirements, change the Nginx user and run the command<\/p>\n Step 3:<\/strong><\/p>\n Add the following file to the block in your website’s Nginx configuration file where you’ve set expiry time for JS\/CSS files<\/p>\n Step 4:<\/strong><\/p>\n Restart the web server. That’s it! To see whether Gzip_static is working on your server or not, refer this answer<\/a> on StackOverflow.<\/p>\n","protected":false},"excerpt":{"rendered":" Like other top\u00a0web servers, Nginx lets webmasters enable Gzip compression for their websites. It can compress scripts and stylesheets in a web page on the fly. The Gzip file’s size is significantly lower than the original file.\u00a0Nginx supports 9 Gzip compression levels.1 is the lowest and 9 is the highest. To gzip a file, Nginx […]<\/p>\n","protected":false},"author":11,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[24],"tags":[11413,7038],"post_series":[],"yoast_head":"\nHow to use Gzip static module?<\/h3>\n
chmod -R nginx_user:nginx_user directory path or file name<\/code><\/p>\n
gzip_static on;<\/code><\/p>\n