Linux Distributions : Nginx : Configuration Basics

Nginx is a light weight 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.

This guide describes how to start and stop Nginx, and reload its configuration, explains the structure of the configuration file and describes how to set up Nginx to serve out static content and how to configure Nginx as a proxy server.


$ sudo apt-get update
$ sudo apt-get install nginx

if the above commands do not work for you click here for more info It can also be found in Ubuntu Software Center. Go, search for it and install from GUI.

Starting, Stopping, and Reloading Configuration

The commands can be used to start / stop / restart the nginx server on a Ubuntu Linux:

$ sudo service nginx start
$ sudo service nginx stop
$ sudo service nginx restart


$ sudo /etc/init.d/nginx start
$ sudo /etc/init.d/nginx stop
$ sudo /etc/init.d/nginx restart
$ nginx -s signal

Where signal may be one of the following:

  • stop — fast shutdown
  • quit — graceful shutdown
  • reload — reloading the configuration file
  • reopen — reopening the log files

for more info on this topic visit the link

General Info

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 (see worker_processes). The way nginx and its modules work is determined in the configuration file. By default, the configuration file is named nginx.conf and placed in the directory /usr/local/nginx/conf, /etc/nginx, or /usr/local/etc/nginx.


After Nginx is started as a daemon it starts listening to port 80 at http://localhost . You can open any browser and invike the address  http://localhost .  You can see

default Landing page for nginx http server

default Landing page for nginx http server

Now you need to configure the Nginx to serve the assets you request from browsers. Nginx consists of modules which are controlled by directives specified in the configuration file. Directives are divided into simple directives and block directives.

Simple Directive:

A simple directive consists of the name and parameters separated by spaces and ends with a semicolon (;).

Block Directive:

A block directive has the same structure as a simple directive, but instead of the semicolon it ends with a set of additional instructions surrounded by braces ({ and}). If a block directive can have other directives inside braces, it is called a context (examples: events, http,server, and location).

Serving Static Content

An important web server task is serving out files (such as images or static HTML pages). You will implement an example where, depending on the request, files will be served from different local directories: /data/www(which may contain HTML files) and /data/images (containing images). To learn more about Serving Static Content click here


For getting the list of all running Nginx processes, the ps utility may be used, for example, in the following way:

$ ps -ax | grep nginx

For more information on sending signals to nginx, see Controlling nginx. To be continued.. Sources:


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s