Flash Sale:75% Off Hosting + Free DomainEnds in13h47m14sView Plans
Hostvento logoHostvento

How to install Nginx on Ubuntu 16.04

This guide shows you how to install the Nginx web server on Ubuntu 16.04. It needs root access, so it is for VPS and dedicated server customers.

How-To Guides2 min read7 steps1 screenshots

What is Nginx?

A web server is a program that sends web pages to visitors. Nginx (say "engine-x") is a fast and popular one. Ubuntu is a Linux system often used on servers.

Tip: Ubuntu 16.04 is old and no longer gets normal updates. Newer Ubuntu versions use the same steps, so you can follow this guide on them too.

Steps

  1. Connect to your server with SSH (a safe way to type commands on a remote server). Log in as root, or add sudo before each command.
  2. Refresh the list of available software:
sudo apt-get update
  1. Install Nginx:
sudo apt-get install nginx -y

This downloads and installs Nginx.

  1. If you use the UFW firewall, let web traffic in. First see the profiles:
sudo ufw app list
  1. Allow normal web traffic:
sudo ufw allow 'Nginx HTTP'

This opens port 80, the usual door for websites. Make sure SSH is allowed too, or you may lock yourself out. Use sudo ufw allow OpenSSH if needed.

  1. Check that Nginx is running:
systemctl status nginx

You should see "active (running)". Press Q to leave the screen.

  1. Open a browser and visit http://YOUR_SERVER_IP. Your server IP is in your welcome email. You should see the "Welcome to nginx!" page.
    Nginx welcome

Handy commands

  • sudo systemctl stop nginx stops the server.
  • sudo systemctl start nginx starts it.
  • sudo systemctl restart nginx stops and starts it again.
  • sudo systemctl reload nginx applies setting changes without a full stop.
  • sudo nginx -t checks your settings for mistakes.

Where things live

  • /var/www/html holds the default web page.
  • /etc/nginx/nginx.conf is the main settings file.
  • /etc/nginx/sites-available holds a settings file for each site.
  • /var/log/nginx holds the logs (records of visits and errors).
Warning: Take a backup of a settings file before you edit it. Run sudo nginx -t before each reload.

Quick recap

  • Nginx is a web server.
  • Run apt-get update, then apt-get install nginx.
  • Allow port 80 in the firewall.
  • Visit your server IP to see the welcome page.
  • Use systemctl to start, stop and restart it.