Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to enable Brotli compression algorithm for Nginx

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)05/31 Report--

In this article Xiaobian for you to introduce in detail "how to enable Brotli compression algorithm for Nginx", the content is detailed, the steps are clear, and the details are handled properly. I hope this article "how to enable Brotli compression algorithm for Nginx" can help you solve your doubts.

What is the brotli compression algorithm

Brotli was first released in 2015 for offline compression of online fonts. Google software engineers released an enhanced version of brotli that includes general lossless data compression in September 2015, with a special focus on http compression. The encoder has been partially rewritten to improve the compression ratio, the encoder and decoder have improved the speed, and the streaming api has been improved to add more compression quality levels. The new version also shows cross-platform performance improvements and reduces the amount of memory required for decoding.

Unlike common general compression algorithms, brotli uses a predefined 120 kilobyte dictionary. The dictionary contains more than 13000 commonly used words, phrases, and other substrings from a large corpus of text and html documents. Predefined algorithms can increase the compression density of smaller files.

Using brotli instead of deflate to compress text files usually increases the compression density by 20%, while the compression and decompression speed is roughly the same. Content encoding types that use brotli for stream compression have been proposed to use "br".

Installation

1. Download brotli

Git clone https://github.com/google/ngx_brotlicd ngx_brotli & & git submodule update-- init

two。 Compile

Add-add-module=/opt/nginx/ngx_brotli to the original compiled configuration

For example

The copy code is as follows:

. / configure-- prefix=/usr/local/nginx-- user=www-- group=www-- with-pcre=/opt/nginx/pcre-8.41-- with-http_ssl_module-- with-zlib=/opt/nginx/zlib-1.2.11-- with-openssl=/opt/nginx/openssl-1.0.2n-- add-module=/opt/nginx/ngx_brotli-- with-http_v2_module

Configuration, join in the http segment

Http {include mime.types; default_type application/octet-stream; sendfile on; tcp_nopush on; keepalive_timeout 65; # brotli compression brotli on; brotli_comp_level 6; brotli_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript image/svg+xml;.

Restart, refresh the page to view the header, and find that there are

Accept-encoding:gzip, deflate, br

As shown in the figure

This means that brotli compression is turned on

Configuration description

Instruction introduction

The following directives are defined:

Brotli, whether to allow dynamic compression of response data. Optional values are on and off, and the default value is off. Examples are as follows:

Brotli on

Brotli_types. When dynamic compression is enabled, mime types for compression is allowed. The default is text/html. Examples are as follows:

Brotli_types text/plain text/css text/xml application/xml application/json text/javascript application/javascript application/x-javascript

Brotli_static, whether you are allowed to find preprocessed compressed files ending in .br. Optional values are on, off, and always. The default value is off. Examples are as follows:

Brotli_static off

Brotli_comp_level, compression level, optional value range is 0x11, default value is 6. Examples are as follows:

Brotli_comp_level 11

Brotli_buffers, the number and size of buffers used to compress response data. Examples are as follows:

Brotli_buffers 16 8k

The window value used by brotli_window,brotli, and the default value is 512k. Examples are as follows:

Brotli_window 512k

Brotli_min_length, the minimum length of the response data, below which the compression operation is not performed using the brotli algorithm. The brotli algorithm uses content-length to determine the length of the response data. Examples are as follows:

Brotli_min_length 20; read here, this article "how to enable Brotli compression algorithm for Nginx" article has been introduced, want to master the knowledge of this article also need to practice and use in order to understand, if you want to know more related articles, welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report