Nginx: Activate GZIP

To speed up the data transfer and to minimize the data transfer GZIP should be activated for JavaScript, CSS and HTML files.

Per default is Gzip is not activated for all relevant mimetypes, so this should be done in the nginx.conf (add in the http section):

gzip on;
gzip_disable "MSIE [1-6]\.(?!.*SV1)"
gzip_proxied any;
gzip_buffers 16 8k;
gzip_types text/plain text/html text/css text/xml application/x-javascript application/xml application/xml+rss text/javascript;
gzip_vary on;

After that Google's page speed test show a significant improvement - lack of GZIP compression is still classified there as a really critical problem, which after activated Gzip is getting better. My next plan is to enable cache times via expires, which currently causes this WordPress blog not to load CSS anymore.

More on the subject nginx and php is available in the corresponding Blog post. Nginx runs with GZIP problem-free and completely stable.

[amazon_link asins=’1491924772,1785280333,B00X40K8M8,B01GI4C982,B01L17AQZ4′ template=’ProductCarousel‘ store=’techbloggernet-21′ marketplace=’DE‘ link_id=’7b653bdf-d937-11e7-9c10-df7e40eff9dd‘]

6 comments

  1. there are two places missing one underlined: gzip_proxiex, gzip_buffers

    otherwise nginx will not start 🙂

  2. I would be interested to know if I can do this for single vHosts, so that the compression is not globally valid?

    1. The same information should also be available in the server {..} block, then it would only work for the respective vhost. But it is only relevant if you have something that is not compatible with gzip, otherwise you could activate it globally like here.

Leave a Reply

Your email address will not be published. Required fields are marked *