Welcome To Nginx! (Part-I)
Tags: nginx, server, beginners, newbie
Published: 2019-04-08 08:30:18

---
title: Welcome To Nginx! (Part-I)
published: true
description: What's Nginx? How to install Nginx?
tags: nginx, server, beginner, newbie
series: Nginx
---


# What is Nginx?

According to Wiki, Nginx is an open source web server which can also be used as a reverse proxy, load balancer, mail proxy, and HTTP cache. The software was created by Igor Sysoev and first publicly released in 2004. [Nginx](https://www.zdnet.com/article/nginx-and-the-future-of-the-web-server/) claims to run 60% of the busiest website on the internet.
We use Nginx mostly as a web server(with the passenger for Rails or golang application) and as a load balancer.


#How to install Nginx in Ubuntu?

Two ways to install Nginx one is from the package and other is from source(recommended)

1. Installing from the package is very simple. This will install the latest stable version

        $ sudo apt-get install nginx

        $ sudo nginx -v
          nginx version: nginx/1.10.2

2. Installing Nginx from source. There are few dependencies we need to install before installing Nginx

        $ sudo apt-get install libpcre3-dev build-essential libssl-dev

    1. libpcre3-dev -> This is basically a regular expression library
    2. libssl-dev   ->  This package is part of OpenSSL implementation of the SSL and TLS for a secure connection

    3. [build-essentail](https://packages.ubuntu.com/xenial/build-essential) -> This package includes GNU C++ compiler, GNU C compiler  and other libraries

You can install on any preferred location, mostly it's installed in /opt or /etc

        $ cd /etc/

        $ sudo wget http://nginx.org/download/nginx-1.10.2.tar.gz

Unzipping the tar file

        $ sudo tar -zxvf nginx-1.10.2.tar.gz

        $ cd /etc/nginx-1.10.2

Configure the build 

        $ sudo ./configure --prefix=/etc/nginx --user=nginx --group=nginx --with-http_ssl_module

        Configuration summary
      + using system PCRE library
      + using system OpenSSL library
      + md5: using OpenSSL library
      + sha1: using OpenSSL library
      + using system zlib library

      nginx path prefix: "/etc/nginx"
      nginx binary file: "/etc/nginx/sbin/nginx"
      nginx modules path: "/etc/nginx/modules"
      nginx configuration prefix: "/etc/nginx/conf"
      nginx configuration file: "/etc/nginx/conf/nginx.conf"
      nginx pid file: "/etc/nginx/logs/nginx.pid"
      nginx error log file: "/etc/nginx/logs/error.log"
      nginx http access log file: "/etc/nginx/logs/access.log"
      nginx http client request body temporary files: "client_body_temp"
      nginx http proxy temporary files: "proxy_temp"
      nginx http fastcgi temporary files: "fastcgi_temp"
      nginx http uwsgi temporary files: "uwsgi_temp"
      nginx http scgi temporary files: "scgi_temp"

Let's build and install with the above configuration

        $ sudo make 
        $ sudo make install

We need to create a separate user and group for Nginx

        $ sudo adduser --system --no-create-home --disabled-login --disabled-password --group nginx 

Installing from source does not include init file for starting and stop the Nginx during the server reboots

        $ sudo vi /etc/init.d/nginx

    {% gist https://gist.github.com/rshiva/6d770f08196a6ac3d631951871acc4c3 %}

Make the above file executable and add it to default run levels

        $ sudo chmod +x /etc/init.d/nginx
        $ sudo /usr/sbin/update-rc.d -f nginx defaults

Now we can start, stop, restart and check status using the below command

        $ sudo service nginx <command>

command -> start, stop, restart, status

You can check if nginx is running using the below command or by visiting the ip address where you have installed

        $ ps aux | grep nginx

![nginx](https://thepracticaldev.s3.amazonaws.com/i/1itl43wg46b56hu0cpn3.png)

![browser](https://thepracticaldev.s3.amazonaws.com/i/0z9i62rtcq2bq39w0407.png)



Congratulation! You have successfully installed Nginx.  

Part II will be about, what different files inside the conf folder does, configuring Nginx to serve an application and what's the role of each block inside nginx.conf file.