Tech Blogs

perspectives for IT decision makers

Nginx Server – Deploying Web Applications

by (August 18, 2015)

Ngnix Server

Nginx is the free, open-source, high-performance HTTP server and reverse proxy, as well as an IMAP/POP3 proxy server. Nginx is popular for its high performance and stability. It comprises a rich feature set and is known for simple configuration. One of the best features of Nginx is the low resource consumption. NGINX Plus is a complete application delivery platform that optimizes the availability and uptime of applications, APIs and services.

Configuration of Nginx/ Windows Server

Recently, for one of my projects, I got an opportunity to deploy Web application (AngularJs application,) on Nginx/Windows server.

In this article, I would like to explain the steps which are required to configure Nginx server. This will be useful for developers and project managers working on Nginx.

Step: 1

Windows

  • Download the Nginx/Windows file
  • You can download it from here

Ubuntu

 User needs to have root privileges before executing the below commands.

  • Open terminal and execute the command as :root@localhost:~# sudo apt-get install nginx
  • You will be prompted for confirmation before it gets installed
  • You will get a confirmation after installation

Step: 2

  • Extract/unzip the downloaded Zip file to location as per your choice. For Example: you can save it “E:\nginx-1.9.3”
  • Navigate to the above location in the command prompt. E:\nginx-1.9.3>
  • Run the following command to start the server

Windows

E:\nginx-1.9.3> start nginx

Ubuntu

root@localhost:~# sudo service nginx start

  • Confirm whether the Nginx process has started or not, by executing the below command:

Windows

E:\nginx-1.9.3>tasklist /fi “imagename eq nginx.exe”

Ubuntu

root@localhost:~# ifconfig eth0 | grep inet | awk ‘{ print $2 }’

  • When you visit your IP address page in your browser, you will see the following message , “Welcome to nginx”
  • In the browser you should see, “Welcomc to nginx” screen

Nginix _ Welcome page

  • If the setup done correctly,, after executing the above command, you should see the output below (for Windows):

E:\nginx-1.9.3>tasklist /fi “imagename eq nginx.exe”
Image Name PID Session Name Session# Mem Usage
============= ===== =========== =========== ============
nginx.exe 5336 Console 1 6,104 K
nginx.exe 5516 Console 1 6,356 K
E:\nginx-1.9.3>

  • One of the processes is the master process and another is the worker process. If nginx does not start, look for the reason in the error log file logs\error.log
  • Nginx/Windows runs as a standard console application (not a service), and it can be managed using the following commands:

Windows

o nginx -s stop fast shutdown

o nginx -s quit graceful shutdown
o nginx -s reload changing configuration, starting new worker processes with a new configuration, graceful shutdown of old worker processes
o nginx -s reopen re-opening log files

Ubuntu

o sudo service nginx start start the server
o sudo service nginx stop stop the server
o sudo service nginx restart restart the server

Step: 3

  • When you have completed  the server setup , it’s time you should configure nginx, to point, to your application

Windows

  • Navigate to “conf” folder under E:\nginx-1.9.3 and open up conf in your favourite text editor

Ubuntu

  • Open up “default” file under below path

root@localhost:~# vi /etc/nginx/sites-available/default

  • Follow the below steps to modify this file :
    • Look for the “server” block in the file
      • Change the value(port) to “listen” or let it  be the default one (viz. set to 80)
      • By default, you will see only one “location” block in this file which will look like

server {

listen       80;

location / {

root   html;

index  index.html index.htm;

}

}

The “location” block here is the place where you define the entry point for your application.

  • For example, as, my application is an AngularJs application, I have modified this location block as below :

Windows

location / {

root   E:/<APPLICATION_NAME>/app;

index  index.html /app/index.htm;

}

Ubuntu

location / {

root /var/www/<APPLICATION_NAME>/app;

index index.html /app/index.htm;

}

Here, I am saying that my entry point for this application is under “/app” folder & index.html is placed under

app/index.html.

  • As AngularJs application requires bower_components and node modules folder (in general). To load an AngularJs application, it requires access to bower_components folder as well, but if you try to load your application with the above configuration it will complain of error 404 in console, which means the application is not able to find the files which are required from bower_components folder. You will see an error like below:

Nginix _ Local host page

Conclusion

Nginx helps your applications to deliver superior performance as well as, render reliability and security. It enhances the complete application delivery platform and has proved to be an incredibly powerful web server and reverse proxy. If you are keen on building amazing applications, Nginx helps you to maintain the reputation and therefore, facilitate better and effective customer experience.

By,

Gourav Ajmani,

Technical Lead, RapidValue Solutions

Sorry no comment yet.

LEAVE A COMMENT

24/7 Toll Free(877)-643-1850(US)

Would you like to know more about us?

  • This field is for validation purposes and should be left unchanged.
Scroll Top