Nginx
# Setting up Nginx to and enabling Gzip compression on Amazon EC2
In this article we will learn how to setup Nginx and how to enable gzip compression for reducing the size of files to be transmitted.
# Set Up Reverse Proxy Server - Nginx
Firstly we need to install on the web server, the epel-release package using yum, (it might be installed on some servers by default)
sudo yum install epel-release
Next, we will install Nginx
sudo yum install nginx
# Enabling Gzip
Gzip is a popular data compression program which is a part of Nginx but needs to be enabled and configured. It helps reduce the size of the files being tranferred, thus making a website load faster.
In nginx all files with the .conf extension from from the /etc/nginx/conf.d
directory are automatically loaded. So that we can easily configure additional modules.
So for Gzip we will create a conf file called gzip.conf using nano editor in the directory etc/nginx/conf.d/
, So navigate to this directory and run the commmand :
sudo nano gzip.conf
And paste the following content in the file.
##
# `gzip` Settings
#
#
gzip on;
gzip_disable "msie6";
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_http_version 1.1;
gzip_min_length 256;
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript application/vnd.ms-fontobject application/x-font-ttf font/opentype image/svg+xml image/x-icon;
Save (CTRL+O then enter) the file and exit the editor (CTRL+X).
sudo service nginx restart
And we have successfully enabled Gzip compression on nginx which will reduce the load time by compressing HTML pages, CSS stylesheets, Javascript files, JSON files, XML files, icons, SVG images and web fonts.
Learn More
- Setting up Nginx to and enabling Gzip compression on Amazon EC2