How to Install NGINX From Source The Simplest Way

Posted By :Harsh Kumar |22nd June 2020



Nginx is a well-known software that acts as both a web server and a proxy. Right now, the market has very few of them who have both these capabilities. So yes, it works as a web server in which you serve web content like HTML, CSS, javascript, etc and along with that the power of proxy adds more advantages to it. Advantages like Load Balancing, Reverse Proxy, Forward Proxy, Caching, and much more. Through this blog post, the Oodles AI team presents a comprehensive guide to install NGINX from source that brings benefits of variety and choice. 


As providers of artificial intelligence services, we at Oodles employ NGINX to build and deploy dynamic machine learning applications including prediction, classification, and more. 




In the IT industry, not every business uses the traditional way of software installation in the server (Linux) viz package installation using a command like apt-get or yum.


So what they do? As we know software like Nginx is open-source so anyone can get its source code. So we use that source code, compile them and then install the software in the system and this is called “source installation”. But after compilation of this type of installation, we did not get the directory structure as we get with the traditional installation (by apt-get or yum). This might be slightly confusing for those who used to install via “yum” or “apt-get”.


Here are simple steps in source installation that can be used to provide you the same familiar Nginx directory structure as we get in a traditional installation.


Install Nginx from the source


  • Nginx is written in C programming language, so we have to install a compiler and other essentials packages after apt update command.

$ sudo apt update

$ sudo apt install build-essential libpcre3 libpcre3-dev zlib1g zlib1g-dev libssl-dev php-fpm

  • Now download any stable package of Nginx. In this case, we are using Nginx1.16.1. You can download other versions of NGINX from the official website.

$ wget

  • Extract it and switch in that directory.

$ tar xvf nginx-1.16.1.tar.gz

$ cd nginx-1.16.1/

  • Now compile the code with the “configure” file. There are lots of build options that you can see by --help. We will use --prefix=<path> to install it in /etc/nginx.

$ ./configure --prefix=/etc/nginx

  • Ready the Makefile by “make” command and install it by “make install”.

$ sudo make

$ sudo make install

  • Now create system service file for Nginx.

$ sudo nano /lib/systemd/system/nginx.service

  • Paste this and if your --prefix=<path> is different, then change according to that.


Description=A high performance web server and a reverse proxy server






ExecStartPre=/etc/nginx/sbin/nginx -t -q -g 'daemon on; master_process on;'

ExecStart=/etc/nginx/sbin/nginx -g 'daemon on; master_process on;'

ExecReload=/etc/nginx/sbin/nginx -g 'daemon on; master_process on;' -s reload

ExecStop=-/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 --pidfile /run/





  • Now start the Nginx and enable it also.

$ sudo systemctl start nginx

Now after all these setups, if you try to look the Nginx directory in /etc/nginx then it will not look as familiar as you expected. The main reason is that you don’t have those three directories that used most i.e “conf.d”, “sites-available” and “sites-enabled”.

  • So to make things easy we will create those directories and set up them to work like they used to do in a traditional installation.

$ sudo mkdir /etc/nginx/sites-available /etc/nginx/sites-enabled /etc/nginx/conf.d

  • Now, we will add two lines in nginx.conf file which will make our created directory work as they supposed to do.

$ sudo nano /etc/nginx/conf/nginx.conf

  • Add these two lines

include /etc/nginx/conf.d/*.conf;

include /etc/nginx/sites-enabled/*;

  • Restart Nginx and all three directories will work like as they worked in package installed Nginx.

Advantages of installing NGINX from source:

  • One can always install the latest version of the software and stay updated for security patches or a new feature.
  • It gives you the freedom to choose the features as per your requirements.
  • You can install it at any location you wish.
  • You can switch to the previous version easily.

$ sudo systemctl enabl


Once installed, NGINX is a great proxy tool for building multiple web apps encompassing machine learning, predictive analytics, and computer vision services.

About Author

Harsh Kumar

He is an enthusiastic employee who has worked on cloud platforms like Azure and AWS and some DevOps tools.

Request For Proposal

Sending message..

Ready to innovate ? Let's get in touch

Notice: Undefined index: HTTP_REFERER in /var/html/www/AI/wp-content/themes/oxides-child/functions.php on line 272

Notice: Undefined index: HTTP_REFERER in /var/html/www/AI/wp-content/themes/oxides-child/functions.php on line 272

Notice: Undefined index: HTTP_REFERER in /var/html/www/AI/wp-content/themes/oxides-child/functions.php on line 272

Notice: Undefined index: HTTP_REFERER in /var/html/www/AI/wp-content/themes/oxides-child/functions.php on line 272

Chat With Us