...

Open source softwares - NGINX

Back to Course

Lesson Description


Lession - #624 NGINX Compression and Decompression


NGINX Compression and Decompression

The pressure interaction diminishes the size of the communicated information. Notwithstanding, since pressure occurs at runtime, it can likewise incorporate significant handling upward which can adversely influence execution. Nginx performs pressure prior to sending reactions to clients however doesn't twofold pack reactions that are now compacted.

Enabling Compression

To enable the compression, add the gzip directive with the on parameter:

gzip on;
By default, Nginx compresses responses only with text/html (MIME type>
. To compress responses with other MIME types, add the gzip_types directive and list the additional types.

gzip_types text/plain application/xml;  
We can define the minimum length of the response to compress, use the gzip_min_length directive. The default is 20 bytes.

gzip_min_length 1000;  


Enabling Decompression

A few clients don't deal with reactions with the gzip encoding technique. Simultaneously, putting away packed information or reactions on the fly and store them in the cache may be attractive. To effectively serve the two clients that endlessly don't acknowledge compacted information, NGINX can de-pressurize information on the fly while sending it to the last option sort of client. To enable runtime decompression, use the gunzip directive.

location /storage/ {  
    gunzip on;  
    ...  
} 
The gunzip directive can be defined in the same context as the gzip directive:

server {  
    gzip on;  
    gzip_min_length 1000;  
    gunzip on;  
    ...  
}  


Sending Compressed Files

To send a compacted document to the client rather than the customary one, set the gzip_static mandate to on inside the suitable setting.

location / {  
    gzip_static on;  
}