Thursday, 26 December 2013

Understanding Nginx

Introduction:   

Nginx (pronounced "engine x") is an open source reverse proxy server for HTTP, HTTPS, SMTP, POP3, and IMAP protocols, as well as a load balancer, HTTP cache, and a web server (origin server). The nginx project started with a strong focus on high concurrency, high performance and low memory usage.it runs on Linux, BSD variants, Mac OS X, Solaris, AIX, HP-UX, as well as on other *nix flavors.

Nginx has one master process and several worker processes. The main purpose of the master process is to read and evaluate configuration, and maintain worker processes. Worker processes do actual processing of requests.The number of worker processes is defined in the configuration file and may be fixed for a given configuration or automatically adjusted to the number of available CPU cores.

==================================================
Controlling Nginx
==================================================
1-> service nginx start  // to start nginx service.
2-> service nginx stop  //  stop nginx services.
3-> service nginx reload  // to reload the configration
4-> service nginx status // to show the status of nginx
5-> ps -ef | grep nginx // list all nginx running processes.

==================================================
Nginx Process Roles
==================================================
 The master process is responsible for the following tasks:

   1->  reading and validating configuration
   2-> creating, binding and closing sockets
   3->starting, terminating and maintaining the configured number of worker processes
   4-> reconfiguring without service interruption
   5-> re-opening log files
  
The worker processes accept, handle and process connections from clients, provide reverse proxying and filtering functionality and do almost everything else that nginx is capable of. In regards to monitoring the behavior of an nginx instance, a system administrator should keep an eye on workers as they are the processes reflecting the actual day-to-day operations of a web server.

===================================================
Nginx Configuration
===================================================

nginx configuration is kept in a number of plain text files which typically reside in /usr/local/etc/nginx or /etc/nginx. The main configuration file is usually called nginx.conf.

The configuration files are initially read and verified by the master process. A compiled read-only form of the nginx configuration is available to the worker processes as they are forked from the master process. Configuration structures are automatically shared by the usual virtual memory management mechanisms.

===================================================
Nginx Logs
===================================================
all nginx log file are in the directory  /var/log/nginx/.




 

Thursday, 12 December 2013

How to make a computer System Dual Boot (Windows and Ubuntu)

There are two different ways to make a system dual boot.

================================================= 
1. Installing Ubuntu on Windows Machine 
================================================= 
 
It is very easy to install Ubuntu on a windows machine.for doing that follow these steps:
1-> make a free drive for Ubuntu operating System.
2-> Insert Live(bootable) CD or USB and install Ubuntu inside the free drive.
3-> after installation remove your Live CD or USB.
4-> Boot your system now you can see options for select operating systems on the boot menu.Ubuntu will be the primary operating system if you dont select any other option then Ubuntu will be boot automatically.
if you want to start windows then select the windows option from the boot menu. 

=================================================
2.Installing window on Ubuntu machine
=================================================
 
This is also an easy task to install windows on Ubuntu.but the diffrence is that you have to repair the grub after installing the windows because windows assumes it's only OS on the machine and it replace the grub with its own boot loader and you have to replace boot loader with grub. for installing windows on Ubuntu follow these steps: 

1-> Boot your system by Ubuntu Live USB or CD.
2-> open Gparted partition Editor
3-> right click on the drive and select Resize/Move option.
4-> give new size in MBs and click on resize option.
5-> now you can see the selected volume is shrinked and free space is unallocated.
6-> Insert bootable windows CD/DVD  and restart the system.
7-> Boot system by bootable CD/DVD and install windows in the free unallocated space.this will create a new partition for windows and install windows in this partition.
8-> after installing windows remove bootable CD/DVD or USB and restart the system.
9-> now you can see your windows operating system will boot there is no option for selecting operating system in boot menu.
 Now repair grub for making system dual boot.
 
==================================================
Repair grub
================================================== 
 
1-> boot from Ubuntu Live USB or CD.
2-> Mount your partition by command:
       sudo mount /dev/sda1 /mnt      // make sure that /dev/sda1 is the correct partition for your system 

3-> Bind other stuff:
      for i in /sys /proc /run /dev; do sudo mount --bind "$i" "/mnt$i"; done
 
4-> chroot into Ubuntu install:
       sudo chroot /mnt
5-> after doing this you are in Ubuntu install now update grub
      update-grub
6-> if you got any error then reinstall grub:
      grub-install /dev/sda
      update-grub
7-> if everything worked without error then you're all set and do      
      exit
     sudo reboot 

if you still having problem and now only Ubuntu is booted then reinstall grub by boot-repair. 

==================================================
 Reinstall grub by boot-repair
================================================== 
1-> Open the terminal and run the following commands to install boot-repair
      
       sudo add-apt-repository ppa:yannubuntu/boot-repair
      sudo apt-get update
      sudo apt-get install boot-repair 

2-> open boot-repair
3-> click on advance option
4-> check Reinstall GRUB,Unhide boot menu, and create a Bootinfo summary(to get help by email or forum)
5-> Change the tab to Grub Location Tab and check The options OS to boot by default and place GRUB into sda
6->Press Apply and Reboot the system 


Now your System is dual boot when you start your system you can see the OS options on boot menu.you can select them and boot desire OS.


 

Thursday, 5 December 2013

WebSocket vs HTTP

How Does WebSocket Compare to AJAX ?

Traditionally, when a web browser loads a web page, it follows these basic steps:

    1.Open a short-lived connection to a web server.
    2.Send one or more requests for a limited number of resources.
    3.Receive resources from the server.
    4.Close the connection to the web server.

This architecture was designed primarily for document retrieval, where web browsers load static web pages from web servers. However, web applications that require frequent, timely updates are not well served by HTTP's traditional document-centric design.

HTTP Problem 1: Unnecessary bandwidth consumption

Every single time the application sends or receives an HTTP request, lengthy HTTP headers are transmitted.

HTTP Problem 2: Server cannot push data to the client

The traditional design of HTTP forces client applications to poll the server for updates.To retrieve a server update, the client asks the server for data, then the server responds to the client.

WebSocket offers the following benefits:

Two-byte per-message overhead (no HTTP header), which translates to lower bandwidth and faster network communications.
    Both the client and the server can initiate a data transfer at any time, which means applications can be built without polling (no Comet, no AJAX). Real-time applications, hence, become more responsive. Data can be delivered to clients instantly, without waiting for client requests.

Why was WebSocket implemented instead of updating HTTP protocol?

WebSockets is better for situations that involve low-latency communication especially for low latency for client to server messages. For server to client data you can get fairly low latency using long-held connections and chunked transfer.

for more details click here