How to Install Nginx - Tutorial (Ubuntu / Debian)
The superfast, opensource Nginx HTTP webserver is becoming very popular nowadays. Fortunately, it’s very simple to install and configure it, as we’ll see in this tutorial.
If you want to know about how to securely set up a Linux VPS (Ubuntu / Debian) click here.
Step 1. Updating your Linux Distro
It’s always good to be updated, so first update your Linux:
$ sudo apt-get update
$ sudo apt-get upgrade --show-upgraded
Step 2. Adding Nginx Official Repository
To have access to the latest versions, you need to add Nginx official repository. First you need to add Nginx repository key, so download the file:
$ wget -O ~/nginx_signing.key http://nginx.org/keys/nginx_signing.key
And add it to your Linux:
$ sudo apt-key add ~/nginx_signing.key
You should see something like: “OK”
Now edit the file /etc/apt/sources.list:
$ sudo nano /etc/apt/sources.list
Add the following two lines to it, replacing codename by your Ubuntu / Debian distribution name:
A) For Ubuntu:
deb http://nginx.org/packages/ubuntu/ codename nginx
deb-src http://nginx.org/packages/ubuntu/ codename nginx
Ubuntu 12.04 codename: precise
Ubuntu 12.10 codename: quantal
Ubuntu 13.10 codename: saucy
Ubuntu 14.04 codename: trusty
B) For Debian:
deb http://nginx.org/packages/debian/ codename nginx
deb-src http://nginx.org/packages/debian/ codename nginx
Debian 6.x codename: squeeze
Debian 7.x codename: wheezy
Save the file by pressing control X, then Y, and then Enter.
Now update your Linux package definitions with the new Nginx repository:
$ sudo apt-get update
You should see some outputs but no error messages, and the following at the end:
“Reading package lists… Done”
Cool, now you can finally install it!
Step 3. Installing Nginx
$ sudo apt-get install nginx
Step 4. Checking Installation
$ /usr/sbin/nginx -v
You should see something like this:
“nginx version: nginx/1.6.0”
You’ll be very close to the latest version, if not on it! But if you’re not, something may have failed on Step 2. Uninstall Nginx and try again from Step 2:
$ sudo apt-get --purge remove nginx
$ sudo apt-get autoremove
Step 5. Starting and Testing Nginx
It’s probably running now, but if not start it:
$ sudo /etc/init.d/nginx start
You should see something like this:
“Starting nginx: nginx.”
If you’re setting up a VPS from scratch, you can now try to access its IP on your browser. You should see something like this:
“Welcome to nginx!”
Congrats! Nginx is installed and listening to port 80 (HTTP). If your server is restarted, you don’t have to worry about Nginx, it’ll be initialized automatically!
Updating Nginx
You can update Nginx at any time running:
$ sudo apt-get update
$ sudo apt-get upgrade --show-upgraded
Stopping Nginx
If you want to stop it just run:
$ sudo /etc/init.d/nginx stop
If you want to know how to configure a website on Nginx and Linux click here.
If you want to know how to securely set up a Linux VPS (Ubuntu / Debian) click here.
Related Posts
How to Configure a Website on Nginx and Linux – Tutorial
How to Password Protect a File or Directory on Nginx
How to Securely Set Up a VPS Server – Tutorial (Ubuntu / Debian)
Interesting Links
Bibliography
“Virtual Private Server – Wikipedia” Wikipedia , n.d. Web. 06 May 2014 <http://en.wikipedia.org/wiki/Virtual_private_server>
Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.