Installing NGINX on an AWS EC2 instance.

NGINX is an open-source, lightweight, and high-performance web server developed by Igor Sysoev and released in 2004. It is one of the most popular web servers in the world. In this article we will set up an NGINX Server on AWS.

Creating an AWS EC2 Instance.

  • Log into the AWS management console.
  • Search for EC2 in the search box and navigate to the suggested search result page.
  • Click on the Launch Instance button on the page. This will open up the configuration panel for the EC2 Instance.
  • Select the Ubuntu-based web server as we would be using the same in this article.
  • Next. Select the instance type We would be using t2.micro which is free tier eligible.
  • AWS ec2 configuration security rules

    Next select ‘Configure Security Group’ and use the same config(this is for this article Ideally you may want to change the sources that can access this instance). Next, select Review and Launch
  • On launch, Select Create a new key pair and hit launch.
  • I am using Putty here(AWS tutorial to set up putty) but in case you are on a Unix based system you should be using SSH. The instruction to which are readily available if you hit the connect button on the screen.

Installing NGINX on the web server.

There are two popular ways to install nginx on the web server

  1. Using the Package Manager.
    Now this is the easiest way to get up and running with NGINX. The package includes nearly all official modules but adding any additional module will be very difficult or even not possible at times.
  2. Building from source. Now, This way is a lot more flexible. We can add any third-party module and latest patches without any trouble.

We will cover both the ways to install NGINX.

As we discussed earlier installing via Package manager is the easiest way to get started. As we used ubuntu server. We get to use apt package manager.

sudo apt-get update
sudo apt-get install nginx

and that is it . Not only will it install ngix but also run it.

Now we will look how to install Nginx by building it from source.

Installing Nginx by building it from source.

  1. Head over to Navigate to the download section. Download the stable version using wget by issuing the command wget <Download url>. For example wget
  2. After the download is completed extract the tar file by issuing the command tar -zxvf <Downloaded NGINX tar>.
  3. CD into the extracted Nginx folder. Now you would need to install a few dev dependencies. To install the dependencies issue the command apt-get install build-essential libpcre3 libpcre3-dev zlib1g zlib1g-dev. Now if you need to have https support also install libssl-dev package.
  4. Now while into the extracted folder run the configure script by issuing the command :
    ./configure –sbin-path=/usr/bin/nginx –conf-path=/etc/nginx/nginx.conf –error-log-path=/var/log/nginx/error.log –http-log-path=/var/log/nginx/access.log –with-pcre –pid-path=/var/run/

    Sbin path is the location of Nginx executable while the conf path is the location of the Nginx configuration.

    Now I got an error telling me that I was missing a few packages the pcre and zlib package. Which I installed in the above command. You may get another dependency error simply install that and run the configure script again.

    Also, add –with-http_ssl_module to the configuration if you want to add SSL support.

    To get a list of all configurations check this link.
  5. Now if the configure script ran without an error run make to compile the source and then run make install. To confirm the installation run command nginx -V. It will return you the configuration along with the Nginx version installed.
  6. To start nginx simply type sudo nginx. Navigate to the Public IP provided to you on ec2 console. You would see something like this(pic attached below) which would confirm your installation.

Leave a Reply