{"id":700,"date":"2016-04-25T08:54:25","date_gmt":"2016-04-25T08:54:25","guid":{"rendered":"https:\/\/loadfocus.com\/blog\/?p=700"},"modified":"2022-08-04T11:47:47","modified_gmt":"2022-08-04T11:47:47","slug":"enable-gzip-compression-on-nginx","status":"publish","type":"post","link":"https:\/\/loadfocus.com\/blog\/2016\/04\/enable-gzip-compression-on-nginx","title":{"rendered":"Enable gzip compression on NGINX"},"content":{"rendered":"<span class=\"span-reading-time rt-reading-time\" style=\"display: block;\"><span class=\"rt-label rt-prefix\"><\/span> <span class=\"rt-time\"> 2<\/span> <span class=\"rt-label rt-postfix\">minutes read<\/span><\/span><p class=\"lead\">During Speed testing of your website or web application using LoadFocus (<a href=\"https:\/\/loadfocus.com\/website-speed-testing\">https:\/\/loadfocus.com\/website-speed-testing<\/a>) on the Advice section you might get the tip that you need to enable compression like in the image below:<\/p>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1874\" height=\"822\" class=\"aligncenter size-full wp-image-706\" src=\"https:\/\/loadfocus.com\/blog\/wp-content\/uploads\/advice_enable_compression.png\" alt=\"advice_enable_compression\"><\/p>\n<p>&nbsp;<\/p>\n<p>Compressing responses often significantly reduces the size of transmitted data.<br \/>\nBecause the compression happens at runtime this can add a big processing overhead which can affect the performance in a negative way.<\/p>\n<p>Nginx if configured correctly compresses the responses before sending them to the clients and does not double compress the responses which have been already compressed.<\/p>\n<p>In the next tutorial we will show how you can enable compression in case you are using Nginx to serve your files.<\/p>\n<p>1. First locate the Nginx configuration file &#8211; nginx.conf<br \/>\n2. Once you located the file open the file and make sure that inside the configuration you can find the following flags:<\/p>\n<pre class=\"lang-java\"><code>\ngzip on;\ngzip_disable \"msie6\";\n\n\ngzip_vary on;\ngzip_proxied any;\ngzip_comp_level 5;\ngzip_buffers 16 8k;\ngzip_http_version 1.1;\ngzip_min_length 1000;\ngzip_types text\/plain text\/css application\/json application\/x-javascript text\/xml application\/xml application\/xml+rss text\/javascript;\n<\/code><\/pre>\n<p>3. Explanation of the flags:<br \/>\n           \r\n            <div class=\"onp-locker-call\" style=\"display: none;\" data-lock-id=\"onpLock565372\">\r\n                <p>\n<strong>gzip<\/strong> on &#8211; enables compression<\/p>\n<p><strong>gzip_disable<\/strong> &#8220;msie6&#8221; &#8211; disable compression for IE6 as IE6 doesn&#8217;t always read and cache gzipped content properly and you end up with mangled code<\/p>\n<p><strong>gzip_vary<\/strong> on &#8211; enables \/ disables inserting the \u201cVary: Accept-Encoding\u201d response header field if the directives gzip, gzip_static, or gunzip are active<\/p>\n<p><strong>gzip_proxied<\/strong> any &#8211; enables or disables gzipping of responses for proxied requests depending on the request and response; the fact that the request is proxied is determined by the presence of the \u201cVia\u201d request header field<\/p>\n<p><strong>gzip_comp_level<\/strong> 5 &#8211; sets a gzip compression level of a response; the values that are acceptable are between 1 and 9; 5 is a good compromise between size and cpu usage<\/p>\n<p><strong>gzip_buffers<\/strong> 16 8k &#8211; sets the number and size of buffers used to compress a response; by default, the buffer size is equal to either 4K or 8K, depending on a platform<\/p>\n<p><strong>gzip_http_version<\/strong> 1.1 &#8211; sets the minimum HTTP version of a request required to compress a response<\/p>\n<p><strong>gzip_min_length<\/strong> 1000 &#8211; specifies the minimum length of the response to compress; the default is 20 bytes; don&#8217;t compress anything that&#8217;s already small and unlikely to shrink<\/p>\n<p><strong>gzip_types<\/strong> text\/plain text\/css application\/json application\/x-javascript text\/xml application\/xml application\/xml+rss text\/javascript<br \/>\n&#8211; by default gzip compression is applied only to responses with MIME type text\/html; to enable it for other types of MIME we need to add them to this flag<\/p>\n<p>4. The flags that are most important are the &#8220;gzip on&#8221; and &#8220;gzip_types&#8221;<\/p>\n<p>5. The directives\/flags that configure compression can be included in the http context or in a server or location configuration block<\/p>\n<p>6. Restart Nginx by doing sudo service nginx restart<\/p>\n<p>7. After you&#8217;ve finishes to enable compression on your server run the LoadFocus speed test again. This time the tip regarding to Enable compression should say that everything is fine.\n<\/p>\r\n            <\/div>\r\n         \r\n\r\n        <br \/>\n<a title=\"website load testing\" href=\"https:\/\/loadfocus.com\/\" target=\"_blank\" rel=\"noopener noreferrer\">LoadFocus.com<\/a> is a Cloud Testing Platform used for Load and Performance Testing for Websites and APIs&nbsp;and&nbsp;Website Speed Testing with Analytics.<\/p>\n","protected":false},"excerpt":{"rendered":"<p><span class=\"span-reading-time rt-reading-time\" style=\"display: block;\"><span class=\"rt-label rt-prefix\"><\/span> <span class=\"rt-time\"> 2<\/span> <span class=\"rt-label rt-postfix\">minutes read<\/span><\/span>During Speed testing of your website or web application using LoadFocus (https:\/\/loadfocus.com\/website-speed-testing) on the Advice section you might get the tip that you need to enable compression like in the image below: &nbsp; &nbsp; Compressing responses often significantly reduces the size of transmitted data. Because the compression happens at runtime this can add a big&#8230;  <a href=\"https:\/\/loadfocus.com\/blog\/2016\/04\/enable-gzip-compression-on-nginx\" class=\"more-link\" title=\"Read Enable gzip compression on NGINX\">Read more &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9,15,6,16],"tags":[128,129,127],"class_list":["post-700","post","type-post","status-publish","format-standard","hentry","category-load-testing","category-page-load-time","category-performance-testing","category-ui-testing","tag-enable-compression","tag-nginx","tag-nginx-compression"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/loadfocus.com\/blog\/wp-json\/wp\/v2\/posts\/700","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/loadfocus.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/loadfocus.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/loadfocus.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/loadfocus.com\/blog\/wp-json\/wp\/v2\/comments?post=700"}],"version-history":[{"count":0,"href":"https:\/\/loadfocus.com\/blog\/wp-json\/wp\/v2\/posts\/700\/revisions"}],"wp:attachment":[{"href":"https:\/\/loadfocus.com\/blog\/wp-json\/wp\/v2\/media?parent=700"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/loadfocus.com\/blog\/wp-json\/wp\/v2\/categories?post=700"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/loadfocus.com\/blog\/wp-json\/wp\/v2\/tags?post=700"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}