Nginx with gzip compression for “text/css” content type

It is by default, that the nginx server when started, does not enable the support for “text/css” content type when using gzip module for compression.

Today, in this post we are going to learn how to add “text/css” type to gzip when using it with nginx server.

Step 1: Check whether the “text/css” being delivered by the server is reaching to the client in the compressed form or not.

inspect element in chrome

From the above, we can see that the content type “text/css” is being delivered to the client without any compression.

Note: Now is the time to add the “text/css” content type for gzip compression via nginx server.

Step 2: Adding “text/css” content type for gzip in nginx.

gzip in nginx main configuration file

In the picture above, we have added the “gzip_types = text/css“.

Step 3: Verify the syntax and reload nginx server.

verify syntax and reload nginx

With the help of following commands, we have verified and reloaded our nginx configuration file:

sudo nginx -t

sudo nginx -s reload

Step 4: Now check whether the added content type is being delivered in compressed form using gzip.

in chrome check whether the content delivered is in compressed form of not

From the picture above, we can now confirm that the content is now being delivered in compressed form as it has now added the following to its “Response Headers“.

Content-Encoding: gzip


In this post, we have learned how to add “text/css” as a content type for compression in the nginx server using gzip module enabled.

More on Nginx:

Comment here