How To Install Nginx on Ubuntu

 In Blog, Internet, Network, Security, Softwares, Web Hosting

lcu14-lightning-talk-nginx-6-638

Introduction

Nginx is one of the most popular web servers in the world and is responsible for hosting some of the largest and highest-traffic sites on the internet. It is more resource-friendly than Apache in most cases and can be used as a web server or a reverse proxy.

In this guide, we’ll discuss how to get Nginx installed on your Ubuntu 14.04 server.

Prerequisites

Before you begin this guide, you should have a regular, non-root user with sudo privileges configured on your server.

When you have an account available, log in as your non-root user to begin.

Step One — Install Nginx

We can install Nginx easily because the Ubuntu team provides an Nginx package in its default repositories.

Since this is our first interaction with the apt packaging system in this session, we should update our local package index before we begin so that we are using the most up-to-date information. Afterwards, we will install nginx:
sudo apt-get update
sudo apt-get install nginx

You will probably be prompted for your user’s password. Enter it to confirm that you wish to complete the installation. The appropriate software will be downloaded to your server and then automatically installed.

Step Two — Check your Web Server

In Ubuntu 14.04, by default, Nginx automatically starts when it is installed.

You can access the default Nginx landing page to confirm that the software is running properly by visiting your server’s domain name or public IP address in your web browser.

If you do not have a spare domain name, or have no need for one, you can use your server’s public IP address. If you do not know your server’s IP address, you can get it a few different ways from the command line.

Try typing this at your server’s command prompt:
ip addr show eth0 | grep inet | awk ‘{ print $2; }’ | sed ‘s//.*$//’

You will get back one or two lines. You can try each in your web browser to see if they work.

An alternative is typing this, which should give you your public IP address as seen from another location on the internet:
curl http://icanhazip.com

When you have your servers IP address or domain, enter it into your browser’s address bar:
http://server_domain_name_or_IP
You should see the default Nginx landing page, which should look something like this:

Nginx default page

This is the default page included with Nginx to show you that the server is installed correctly.

Step Three — Manage the Nginx Process

Now that you have your web server up and running, we can go over some basic management commands.

To stop your web server, you can type:
sudo service nginx stop

To start the web server when it is stopped, type:
sudo service nginx start

To stop and then start the service again, type:
sudo service nginx restart

We can make sure that our web server will restart automatically when the server is rebooted by typing:
sudo update-rc.d nginx defaults

This should already be enabled by default, so you may see a message like this:
System start/stop links for /etc/init.d/nginx already exist.

This just means that it was already configured correctly and that no action was necessary. Either way, your Nginx service is now configured to start up at boot time.

 

Reference

www.wikipedia.com

Recent Posts

Leave a Comment

Start typing and press Enter to search