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 in Nginx

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

This article is to share with you about how the Brotli compression algorithm is enabled in Nginx, the editor thinks it is very practical, so I share it with you to learn. I hope you can get something after reading this article.

Brotli is a new data format that provides a 20-26% higher compression ratio than Zopfli.

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

Ngx_brotli defines the following directives:

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; above is how the Brotli compression algorithm is enabled in Nginx. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please 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

Servers

Wechat

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

12
Report