Nginx

Nginx is an alternative web browser to Apache, in essence they both do the same job, however nginx is considered as an light weight alternative to Apache. There is an number of ways to install nginx, however you would need to add the nginx repositories to the server as they isn’t present by default. The server which we will be using will be Ubuntu 14.04 LTS (Trusty Tahr).

To add the repositories, we would need root privileges on the server and we will be editing the following file. We will keep the contents of the file as it is but we will be adding two lines to the end of the file.

Stable

sudo nano /etc/apt/sources.list
#deb cdrom:[Xubuntu 14.04.1 LTS _Trusty Tahr_ - Release amd64 (20140723)]/ trusty main multiverse restricted universe

# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.
deb http://gb.archive.ubuntu.com/ubuntu/ trusty main restricted
deb-src http://gb.archive.ubuntu.com/ubuntu/ trusty main restricted

## Major bug fix updates produced after the final release of the
## distribution.
deb http://gb.archive.ubuntu.com/ubuntu/ trusty-updates main restricted
deb-src http://gb.archive.ubuntu.com/ubuntu/ trusty-updates main restricted

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team. Also, please note that software in universe WILL NOT receive any
## review or updates from the Ubuntu security team.
deb http://gb.archive.ubuntu.com/ubuntu/ trusty universe
deb-src http://gb.archive.ubuntu.com/ubuntu/ trusty universe
deb http://gb.archive.ubuntu.com/ubuntu/ trusty-updates universe
deb-src http://gb.archive.ubuntu.com/ubuntu/ trusty-updates universe

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu 
## team, and may not be under a free licence. Please satisfy yourself as to 
## your rights to use the software. Also, please note that software in 
## multiverse WILL NOT receive any review or updates from the Ubuntu
## security team.
deb http://gb.archive.ubuntu.com/ubuntu/ trusty multiverse
deb-src http://gb.archive.ubuntu.com/ubuntu/ trusty multiverse
deb http://gb.archive.ubuntu.com/ubuntu/ trusty-updates multiverse
deb-src http://gb.archive.ubuntu.com/ubuntu/ trusty-updates multiverse

## N.B. software from this repository may not have been tested as
## extensively as that contained in the main release, although it includes
## newer versions of some applications which may provide useful features.
## Also, please note that software in backports WILL NOT receive any review
## or updates from the Ubuntu security team.
deb http://gb.archive.ubuntu.com/ubuntu/ trusty-backports main restricted universe multiverse
deb-src http://gb.archive.ubuntu.com/ubuntu/ trusty-backports main restricted universe multiverse

deb http://security.ubuntu.com/ubuntu trusty-security main restricted
deb-src http://security.ubuntu.com/ubuntu trusty-security main restricted
deb http://security.ubuntu.com/ubuntu trusty-security universe
deb-src http://security.ubuntu.com/ubuntu trusty-security universe
deb http://security.ubuntu.com/ubuntu trusty-security multiverse
deb-src http://security.ubuntu.com/ubuntu trusty-security multiverse

## Uncomment the following two lines to add software from Canonical's
## 'partner' repository.
## This software is not part of Ubuntu, but is offered by Canonical and the
## respective vendors as a service to Ubuntu users.
# deb http://archive.canonical.com/ubuntu trusty partner
# deb-src http://archive.canonical.com/ubuntu trusty partner

## This software is not part of Ubuntu, but is offered by third-party
## developers who want to ship their latest software.
deb http://extras.ubuntu.com/ubuntu trusty main
deb-src http://extras.ubuntu.com/ubuntu trusty main
deb http://nginx.org/packages/ubuntu/ trusty nginx
deb-src http://nginx.org/packages/ubuntu/ trusty nginx

Our current OS is Ubuntu on version 14.04 LTS Trusty Tahr, this is why we have listed "trusty".

If you have Ubuntu 10.04 Lucid Lynx, please use lucid.
If you have Ubuntu 12.04 Precise Pangolin, please use precise.
If you have Ubuntu 14.04 Trusty Tahr, please use trusty.
If you have Ubuntu 14.10 Utopic Unicorn, please use utopic.


If your using Debian, you would use the following two lines instead.

deb http://nginx.org/packages/debian/ wheezy nginx
deb-src http://nginx.org/packages/debian/ wheezy nginx 
If you have Debian, you would need to rename the two lines with Debian and OS name.

If you have Debian 6, please use squeeze.
If you have Debian 7, please use wheezy.


Mainline

To install the main line, there is some subtle changes in which you need to make with the Nginx source, when your adding them to /etc/apt/sources.list. Here is the lines to add under Ubuntu.

deb http://nginx.org/packages/mainline/ubuntu/ trusty nginx
deb-src http://nginx.org/packages/mainline/ubuntu/ trusty nginx

As we can see there to specify the main line repositories, we would add the word ‘mainline‘, naturally we would still need to specify the OS name, in this case it is still trusty.


For Debian, we will use the following extract for our mainline nginx installation:

deb http://nginx.org/packages/mainline/debian/ wheezy nginx
deb-src http://nginx.org/packages/mainline/debian/ wheezy nginx

Nginx key

As the respositores are non-official repositories from Ubuntu, you will get an warning about the repository which we have just added:

Get:31 http://nginx.org trusty/nginx Sources [651 B] 
Get:32 http://nginx.org trusty/nginx amd64 Packages [961 B]               
Get:33 http://nginx.org trusty/nginx i386 Packages [961 B]                
Ign http://nginx.org trusty/nginx Translation-en_GB                       
Ign http://nginx.org trusty/nginx Translation-en
Fetched 2,407 kB in 3s (603 kB/s)
Reading package lists... Done
W: GPG error: http://nginx.org trusty Release: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY ABF5BD827BD9BF62

To resolve this issue, we need to install the nginx key, this can be done with the following command below. This will simply download the nginx key. Once downloaded we would still need to install the key.

sudo wget http://nginx.org/keys/nginx_signing.key
--2015-02-03 23:05:19--  http://nginx.org/keys/nginx_signing.key
Resolving nginx.org (nginx.org)... 206.251.255.63
Connecting to nginx.org (nginx.org)|206.251.255.63|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1559 (1.5K) [text/plain]
Saving to: ‘nginx_signing.key’

100%[======================================>] 1,559       --.-K/s   in 0s      

2015-02-03 23:05:19 (115 MB/s) - ‘nginx_signing.key’ saved [1559/1559]
To install key
sudo apt-key add nginx_signing.key

If the key is installed successfully, you will get an “OK” after you have pressed enter. Now we can get started in installing nginix to our server. We will first check for all updates with sudo apt-get update, this should update normally without presenting any issues as we have installed the nginx key. Now we can install nginx simply by specifying its name.

sudo apt-get install nginx
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following NEW packages will be installed
  nginx
0 to upgrade, 1 to newly install, 0 to remove and 5 not to upgrade.
Need to get 384 kB of archives.
After this operation, 1,005 kB of additional disk space will be used.
Get:1 http://nginx.org/packages/ubuntu/ trusty/nginx nginx amd64 1.6.2-1~trusty [384 kB]
Fetched 384 kB in 1s (336 kB/s) 
Selecting previously unselected package nginx.
(Reading database ... 144594 files and directories currently installed.)
Preparing to unpack .../nginx_1.6.2-1~trusty_amd64.deb ...
----------------------------------------------------------------------

Thanks for using nginx!

Please find the official documentation for nginx here:
* http://nginx.org/en/docs/

Commercial subscriptions for nginx are available on:
* http://nginx.com/products/

----------------------------------------------------------------------
Unpacking nginx (1.6.2-1~trusty) ...
Processing triggers for ureadahead (0.100.0-16) ...
ureadahead will be reprofiled on next reboot
Setting up nginx (1.6.2-1~trusty) ...
Processing triggers for ureadahead (0.100.0-16) ...

At this stage we have now successfully installed nginx to our server and we is now ready to build our website using nginx as our web server.