Installing Nginx on Ubuntu 16.04

What’s Nginx?

Nginx is a popular open-source web server used for hosting sites known for its high-performance, simple configuration and stability.

What You’ll Need

Before proceeding with this tutorial you’ll need a root user account and Ubuntu 16.04 running on your server.

Installing Nginx

Ubuntu has Nginx in its default repositories, so after we update our local package index, we can start installing nginx.

sudo apt-get update

sudo apt-get install nginx

Configuring your Firewall

We need to modify some things in our firewall to give Nginx access. List the firewall’s configurations with the following line:

sudo ufw app list

And you should get the following applications:

Output

Available applications:

Nginx Full

Nginx HTTP

Nginx HTTPS

OpenSSH

Nginx Full – opens port 80 (unencrypted traffic) and port 443 (TLS/SSL encrypted traffic)

Nginx HTTP – opens only port 80

Nginx HTTPS – opens only port 443

To enable one of the applications you type:

sudo ufw allow 'Nginx HTTP'

To check your status type the following:

sudo ufw status

Checking your Server

By now your web server should be running, but you can check with the following command:

systemctl status nginx

And an output should appear saying the service started successfully.

Or you can type you server’s IP address/domain into your browser:

http://server_domain_or_IP

And Nginx’s default landing page should appear.

Nginx Commands

Since you now have a functional server let’s list a few basic commands that you’ll use later on.

To start your web server if it is stopped:

sudo systemctl start nginx

If you want to stop your server, type:

sudo systemctl stop nginx

For restarting server, type:

sudo systemctl restart nginx

To reload Nginx (if you’re configuring something and what to see the changes you’ve made):

sudo systemctl reload nginx

If you want to disable Nginx start up at boot feature, type:

sudo systemctl disable nginx

And to re-enable it:

sudo systemctl enable nginx

Nginx files and directories

Here we will discuss some files and directories which you’ll be needing in future configurations and installations.

  • /var/www/html: web content; by default it only contains Nginx’s landing page;
  • /etc/nginx: configuration directory, all Nginx configuration files can be found here;
  • /etc/nginx/nginx.conf: main Nginx configuration file, here you can modify Nginx global configurations;
  • /etc/nginx/sites-available: all server block configs are made in this directory;
  • /etc/nginx/sites-enabled/: here enable server blocks are stored. Nginx will not use sites-availableif it is not linked to this directory.
  • /etc/nginx/snippets: contains configuration fragments that can be used in other Nginx configurations;
  • /var/log/nginx/access.log: requests to your web server are stored in this log file;
  • /var/log/nginx/error.log:this log contains Nginx errors.

Conclusion

If you’ve made it this far you should now have Nginx installed and running and you can start hosting sites on your server. Obviously there is so much more you can do with Nginx, but here we just covered the installation part, a simple yet important step in your journey of becoming a web master.

Need a reliable server to start hosting your sites? Check out our high performance Linux VPS starting at 2GB RAM for only $5/mo.

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments