Deploy your application with Nginx

Nginx is a web server Software which can also be used as a reverse proxy, load balancer, mail proxy and HTTP cache. Nginx is a free, open-source, high-performance HTTP server and reverse proxy, as well as an IMAP/POP3 proxy server. Nginx is known for its high performance, stability, rich feature set, simple configuration, and low resource consumption.

In above Introduction it has been mentioned that Nginx is a Webserver Software then question arises in our mind.

What is Web Server Software ?

Web server Software decides what get served.

  • A web server is a program that uses HTTP (Hypertext Transfer Protocol) to serve the files that form web pages to users in response to their requests, which are forwarded by their computer’s HTTP clients.
  • So all your static files and sometimes dynamic routes are identified by it and they map the path the component of URL to the local files and application.

Some Key Points regarding Nginx :

  1. Nginx is Pronounced as “Engine X”.
  2. It is a high performance web server designed to deliver large amounts of static contents at good speed by efficiently using system resources.
  3. Main Purpose of developing Nginx is to tackle C10K problem which means serving 1000 concurrent connections.
  4. Nginx can be used as standalone webserver, or serve in front of other webservers as a reserve proxy.

Advantages of Nginx

      • Nginx is fast
    • It comes with additional features to maintain SSL/HTTP,GZIP cache headers, load balancing is fast

and a lot of further stuff.

  • Nginx uses an asynchronous event-driven model which provides more predictable performance load.
  • It can be used as reserve proxy.
  • It paid version comes with advance security and DDOS mititgation.

Installing nginx is very Simple

You can install and perform Nginx Operations using following these commands

Nginx Command
To install Nginx sudo apt-get install nginx
To Satrt Nginx sudo service nginx start
To Stop Nginx sudo service nginx stop
To restart Nginx sudo service nginx restart
To reload Configuration sudo service nginx reload

Now let’s ready for installing Nginx so just execute command and Nginx will be installed on your machine.


sudo apt-get install nginx

Install-nginx

Start Nginx

strat-nginx

After executing this command your Nginx server will be started now go to your web browser and type localhost and press enter after that your page will be look like this.

It means our server is started now and now, it’s time to host your application on Nginx and for that purpose to we have need to make some changes inside our Nginx default file which is available inside


/etc/nginx/sites-available 

So, open your terminal and type command


cd /etc/nginx/sites-available

Now, execute ls command inside your terminal and you will found that there is a file “default” is existing inside that folder

So open default folder and make some changes after executing following command


sudo nano default

Now, Your default file has been opened now remove all lines from file and for doing so just type command ctrl+k


server {
#Lines with hash means commented lines
#root location of file 
#As in my case my file location is root /home/dheeraj/Blogs/nginxExample;
 root /home/dheerajBlog/nginxExample;
}

Note: nginxEngine folder it contains a index.html file which is looks like

index.html



<html> 
<head> 
<!--- Importing bootstarp files --> 
<!-- CSS files -->  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous"> 
<!--Scripting files --> 
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script> 
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script> 
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script> 
<!--Scripting files --> 
</head> 
<body> 
<div class="container-fluid">
<h2 class="bg-success text-white text-center">
Hello Nginx Server</h2>
<h7>this is my first nginx Example ....</h7>
 </div> 
</body> 
/html> 

Now Open Your terminal and type command


sudo service nginx start

After that in Browser type


localhost

And reload your page and your page will be look like this

MongoDb installation on Windows 32 bit System
Rest API in Angular 4
Angular 4 Service Tutorial
Angular 4 Component Tutorial