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.

 

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:

And you should get the following applications:

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:

To check your status type the following:

Checking your Server

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

And an output should appear saying the service started successfully.

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

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:

If you want to stop your server, type:

For restarting server, type:

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

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

And to re-enable it:

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.


Vlad

Tech Support

Leave a Comment

LIMITED TIME SPECIAL 💀

Enter your email below to get 20% OFF on any of our Linux VPS plans and receive weekly deals on our services!