Getting started with Nginx

Points To Remember

  • Nginx is pronounced as Engine-x
  • It is open source
  • It is a High performance HTTP server and Reverse proxy
  • It does not rely on thread to handle requests. Thus it can serve thousands of concurrent requests.
  • It works on scalable event driven (asynchronous) architecture. 

Getting started with NGINX

  • Install nginx
    sudo apt-get install nginx
  • Check the status of the server
    sudo service nginx status
  • Start the nginx server
    sudo service nginx start 
Go to the browser and enter the url http://localhost you will see the following screen.

Our nginx server is up and running.

Viewing the NGINX configuration files.

You can go to the folder /etc/nginx to view the Nginx configuration files.

The image above shows how the nginx files looks like.

For getting started the important files you should be familiar to are

  1. mime.types it includes all the mime types the the ngnix server will support.
  2. nginx.conf it contains most of the configuration that is required for a normal application. It contains the following things
    • events block - it contains the number of connections to support
    • http block - it contains the  server settings, logging settings and other basic settings.
    • mail block - for pop/imap services
  3. sites-available - This is where you define your server configurations for different sites/applications.
  4. sites-enabled- it contains the soft link to the sites/applications that are defined in sites-available.

How to Configure Nginx to serve a new Site

  • Go to /etc/hosts create a new entry there e.g
  • Create a new server configuration in sites-available folder e.g
     listen   80;
     root  /home/ekansh/;
     index index.html;
     location / {
  • Enable this site by adding a soft link to this file
    sudo ln -s /etc/nginx/sites-available/
  • Now restart the nginx server using command
    sudo service nginx restart
Go to the browser and open the url you will be able to see the html page on the home directory by name index.html

No comments :

Post a Comment