nginx.org (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:
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:
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.
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 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
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
Next step is to download their signing key to authenticate the nginx repository:
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.
sudo apt-get install build-essential
sudo apt-get install libpcre3 libpcre3-dev
sudo apt-get install zlib1g-dev
Let's kick this off with the good old download phase:
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:
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