Sharing a list of MIME types using GZIP and BROTLI in NGINX

I want to enable GZIP and Brotli compression using NGINX. I have to provide everyone with my own list of MIME types, for example in my nginx.conf:

gzip_types text/plain text/css ...etc; brotli_types text/plain text/css ...etc; 

How to create one list of MIME types that can be used by both settings?

+6
source share
1 answer

This is a fairly simple task to establish the synchronization of two lists, since the number of MIME types that can benefit from compression is about 20.

If you absolutely need to manage the list from a central location, I would suggest exploring the development of the Ansible play to bring the Nginx configuration to the server.

The part of the Ansible play that is relevant for pressing the appropriate configuration will look like this:

 - name: "Set fact for compressible MIME types" set_fact: compressibles: - "text/css" - "application/javascript" - "..." - name: "copy {{ item }} conf.d config file" template: src: "{{ item }}.conf.j2" dest: "/etc/nginx/conf.d/{{ item }}.conf" with_items: - brotli - gzip notify: reload nginx 

gzip.conf.j2:

 gzip on; gzip_types {{ compressibles|join(' ') }}; # whatever else you think is relevant for gzip configuration # ... 

brotli.conf.j2

 brotli on; brotli_types {{ compressibles|join(' ') }}; # whatever else you think is relevant for brotli configuration # ... 
0
source

All Articles