tutorials questions & answers
by

Installing Nginx on Ubuntu

TAGS:
  • nginx
  • ubuntu
  • installation

Installing Nginx on Ubuntu Desktop/Server Versions


Nginx

[nginx.org](http://nginx.org/ "Nginx official home page") (engine x) is a reverse and proxy server, mail server and also an generic TCP/UDP proxy server - free, open-source and high-performant. It is often selected by administrators for it's resource efficiency and responsiveness under load. It's light weight resource utilization and the ability of scaling easily on minimal hardware added with asynchronous - events-driven architecture make it a server loved by a lot of administrators, developers and engineers.


This tutorial will be split into 3 sections:

  1. Section 1 will be covering Nginx installation with apt-get (version can be older as latest)
  2. Section 2 covers installing nginx with Pre-Built Packages
  3. Section 3 installing latest version from source

PREREQUISITES

What do you need to follow along:

  1. You have minimal Ubuntu 12.10 (Quantal Quetzal) installed - this tutorial will is based on Ubuntu 16.04.1 LTS (Xenial Xerus) - on your VPS Server from [vpsserver.com](http://vpsserver.com/ "VPSSERVER official home page"). If you don't have it, one can be purchased from 5€/month, just follow this link: https://www.vpsserver.com/plans/
  2. Any kind of SSH Client to connect to the VPS Server - Windows( http://www.putty.org/ ) - for Unix systems you can use the SSH Tool in your terminal
  3. You have the knowledge to run basic bash commands in Linux / MacOSX

Installing with Ubuntu Package Manager (apt-get)

Installing Nginx on Ubuntu is a pretty easy task if you decide to install it using the built in package manager tool apt-get.

Before doing any kind of apt-get actions I always say it a good practice to update the repository information. Let's do that now with:

`

sudo apt-get update

`

After the repositories are updated it all comes down to running this simple command:

`

sudo apt-get install nginx

`

This simple command will check the apt-get repository for the package named "nginx" and install it using the right rights.

Before you continue with the installation you have to answer the question if you want to continue or not.

After the installation is done there's only one thing left to do: make sure that the Nginx package was successfully installed:

`

nginx -v

`

If everything went alright you should see this as the feedback: nginx version: nginx/1.10.0 (Ubuntu) indicating you are good to go.

All that is left for you to do is connect your Web Browser to the IP you used to SSH into your VPS.

You should see a Welcome page indicating that nginx was successfully installed and is up and running.

Reminder

If you still remember nginx -v command said that nginx version: nginx/1.10.0 (Ubuntu) was installed. The version installed using apt-get doesn't have to always be Up-to-date with the latest version available.

My advice consolidate with the version documentation on nginx.org to see what's under the hood in that version.

If you checked the versions and found out that a newer version exist and has something that you need than keep on reading.


Installing with Pre-Built packages

Installing from the Mainline Pre-Built packages is a big advantage to the "standard" install with apt-get, because you bind your apt-get nginx repository with the Pre-Built newest version package which is refreshed from the nginx team.

You can also choose to bind to the stable Pre-Built packages, but that's for you to decide and me to show you how to get it set up.

The first step is to add the repositories links to your /etc/apt/sources.plist file.

For detailed info read more here: http://nginx.org/en/linux_packages.html#mainline

echo "deb http://nginx.org/packages/mainline/ubuntu/ xenial nginx" >> /etc/apt/sources.list echo "deb-src http://nginx.org/packages/mainline/ubuntu/ xenial nginx" >> /etc/apt/sources.list

These 2 command append the string inside "" to your /etc/apt/sources.list

Next step is to download their signing key to authenticate the nginx repository:

wget http://nginx.org/keys/nginx_signing.key

This will download the key into the current directory you are in.

Before you can start with the installation you have to add the downloaded key to the apt program keyring:

sudo apt-key add nginx_signing.key

Your command line should say: OK and you are good to go with the installation.

To initiate the installation issue these 2 commands(apt-get update is !important - it reloads the repositories and takes the repo with the nex nginx version):

sudo apt-get update sudo apt-get install nginx

After installation check if nginx was successfully installed:

nginx version: nginx/1.11.4

Congratulations you are set to start using your nginx installation which will follow the new versions that are pushed on the nginx mainline.


Installing from source

Only for the experienced ones... And those who want total control of the installation process and the methods nginx will have available.

PREREQUISITES

  1. Build tools have to be installed: sudo apt-get install build-essential
  2. PCRE must be installed: sudo apt-get install libpcre3 libpcre3-dev
  3. zlib installed: sudo apt-get install zlib1g-dev

Let's kick this off with the good old download phase:

wget http://nginx.org/download/nginx-1.11.4.tar.gz

After it downloads we have to unpack it (this will unpack it to the active directory with folder name: nginx-1.11.4 and traverse into it):

tar -zxvf nginx-1.11.4.tar.gz && cd nginx-1.11.4

Next step is running the configure script which checks which methods nginx can use and it creates a Makefile when it's done. I'll be using the standard execution but for more info on what you can control have a look at: http://nginx.org/en/docs/configure.html !

./configure && make && make install

This will install nginx into: /usr/local/nginx

All is left to do is to add the PATH variable of the nginx binary to bash PATH (so you can execute the nginx command anywhere in your terminal) - here's a one-liner that takes care of it all (add the PATH to .bashrc & reloads it & checks the nginx version & shows which nginx binary is run);

echo "export PATH=$PATH:/usr/local/nginx/sbin" >> ~/.bashrc && source .bashrc && nginx -v && which nginx


Thank you for checking out my tutorial and if you have anything to add or maybe correct you are more than welcome to contact me!

Brought to you by: Nejc Vukovic

comments (0)

    leave comment

    Please choose login or register to comment in this thread.

    Start now for as low as $5 a month!

    • 8 Characters
    • 1 Uppercase Atleast
    • 1 Number Atleast