Compression in web servers is used to improve website loading performance, and is often measured and evaluated by search engines. Enabling gzip compression in Nginx is quite easy, since it’s already there in the main config file.

Just edit the /etc/nginx/nginx.conf file (or any other host file you have), and make it look like this:

 

#uncomment the line below:
gzip  on;
#and add:
gzip_disable "msie6";
gzip_vary on;
gzip_proxied any;
gzip_comp_level 9;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;

By this, basically we told Nginx to enable gzip compression, set the memory buffers and told it what to compress (we wouldn’t want it to compress already compressed content, etc).

You can change the level of compression according to your CPU speed and needs. It takes a little experimenting to see which setting fits the server best.

service nginx restart