In the last lecture we were talking about the Http headers, which were except encoding and content
encoding.
So in this video we'll actually start with Nginx to see on how we can configure our Nginx server to
support compression as well as decompression.
So let's go to the Nginx directory and let's open nginx.conf.
So if we go below there is a directive called as GZip on.
So that means that the Nginx will support GZip based compression utility.
Now just having GZip on will not actually start to compress your data.
You have to have more directives.
So let's start with one which is GZip, underscore types.
I'll say text plain, maybe text CSS, say text, maybe XML.
Text JavaScript.
And so on.
So it is necessary to specify on what type or what mime type of data that we have to compress.
So all of these are the mime types.
So once the server sees the accept encoding header, which is GZip from the client side, and if the
get request has either one of these particular type, then the server will actually compress the data
in send.
Now generally the reason why we specify this is because we don't want to compress data such as image
file or video file because there won't be much of compression that can be applied on that.
So compression can be mostly applied into text based data, which can be CSS, XML, JavaScript, HTML
or other things.
So one more important directive is the gzip underscore disable, which has to be MSI.
Let's see.
One, two, six.
A forward.
So the reason why we have included this is because the Microsoft Internet Explorer from version 1 to
6 actually does not work well with GZip properly.
It does not support it.
So this is the reason why we have to implicitly specify that disable the GZip for anything or any Microsoft
Internet Explorer browser from version 1 to 6.
So this is one of the important parameters that you have to mention.
So let's save the file and let's do Nginx and everything is successful.
Let's reload the Nginx.
Okay, so the engine seems to be working properly.
So let's go to temp and I've created a directory called as test and we'll use the curl utility and see
how the compression has helped.
So I'll say curl, let's say curl followed by the http example.com.
Followed by the sshd underscore config dot txt.
And save it as a c1 dot txt.
Okay if I do?
This is the size.
Now let's run the same command with Hyphen H.
I'll explain what this is.
Let's accept encoding which would be GZip.
And let's save this as c two dot txt.
Let's do ls again.
And now you see the difference between two files.
So let's see what we have done through both the curl commands.
So this was one of the first command and this was the second command.
Okay.
So in the first command we are trying to curl for sshd underscore config dot txt and the output is stored
in c one dot txt file.
However, for this particular request there is no except hyphen encoding header.
So the server will not compress the data.
However, for the second request we are explicitly specifying that the curl will support GZip based
compression.
So now server will compress the data with GZip and will send it to the curl utility.
And we are storing it as c two dot txt.
Now if we look into the size between c one and c two, c two, you will see the c two is much more less
than that of c one dot txt.
So from this you can determine that the compression has worked, provided the hyphen encoding is sent
from the curl utility.
So by default curl does not send it and you have to explicitly mention that.
Now, one more important thing that you can mention.
In the enginex configuration file is the.
GZip compression level.
Let's say nine.
So GZip has compression level which starts from 1 to 9.
So one is the fastest, but the compression level is very less.
In nine, the compression ratio is great, but it takes a lot of computational power to compress that
much amount of data.
So ideally in server you should select between 1 to 9.
So a lot of people select six, which is ideal to them.
Many people select nine, provided you have enough amount of computational resources to compress that
much amount of data.
So this is it about the.
Compression and decompression as far as the engine is concerned.
So I hope this has been useful for you, and I'd like to thank you for viewing.