Ever wanted to host your own website? Have a spare PC laying around (even REALLY old) that you can use? This tutorial is going to show you how!

Now, three disclaimers I am going to give:

  • This tutorial will be done nearly entirely with the command line. I personally find it much easier, and less time consuming to do this sort of work in a terminal, plus it’s good practice to anyone who decides they want to work with remote servers in the future for hosting a website off-site.
  • This tutorial will not be covering hardening, SSL certificates, advanced HTML/CSS/Javascript nor advanced DNS work. This is simply going to show you how to put a website up for others to view, it’s up to you to design it!
  • This tutorial serves as a test, to see the interest in this sort of thing on Ghacks. If reception is good, I will cover more advanced topics relating to server work, webhosting, email servers, hardening, etc. If you the reader is more interested in keeping things on a ‘home user’ level, do let me know in the comments!

For this, we will be using the Nginx webserver. There are multiple webservers available, but the two most common are Apache and Nginx. My production servers all use Nginx, and without drowning you with information about why, I’ll summarize it as, “Better performance.”

This tutorial will assume you are running Debian, Ubuntu, or one of their derivatives; as they are the most common distributions, and Debian is one of the most popular server operating systems anyway due to it’s rock solid stability.

html sample

Hosting your own website: The Process

Note: The first thing we want to do is ensure that our system has the latest updates:

  • sudo apt update
  • sudo apt upgrade

If you have any updates to do, agree to them and let it happen.

Next, we want to install nginx:

Nginx should only take a few moments to install, it’s very small. Once that is done, you’ll want to make sure that nginx is running:

  • sudo sysemctl status nginx

OR if not using systemd:

  • sudo service nginx status

You should receive some text, telling you something like:

  • nginx start/running, process 5142 <-- If you are using sysinit
  • and for systemd: Active: active (running) since XXX XXXXX XXXX (Today’s date and time)

Testing nginx

A good way to test nginx and reconfirm that it’s running, is to visit the test page! (That’s right, from the moment nginx installed itself, you have been broadcasting a test page to the internet!)

First, we need to find out what our IP address is. If you are connected to the internet via ethernet, you can try this command:

  • ip addr show eth0 | grep inet | awk ‘{ print $2; }’ | sed ‘s//.*$//’

Or, you can use a command called curl, used to transfer URL data, to check on a website called http://icanhazip.com:

Now that we have our IP address, enter it into your webbrowser using a different device than the machine you are running nginx on:

You should find the default nginx welcome page!

Directories, and further setup tips

The last part of this very simple tutorial, is knowing the important nginx directories.

  • /var/www/html or /var/www/ <- - Where your website is stored. You will want to replace “index.html” with your own index file / your homepage!
  • /etc/nginx <-- The main nginx configuration directory, where all the important files you may one day need to edit are stored, such as nginx.conf
  • /etc/nginx/sites-available <--The main directory where configurations or “Server blocks” for each website you host, are stored. This is where the files you need to edit in the future for changing things like SSL are stored.
  • /etc/nginx/sites-enabled <-- files from “Sites Availble” must be symlinked here, before nginx will serve the page to the web.

This is the absolute barebones basic of nginx hosting.

Domain names, and final thoughts

Having nginx installed and running is fine and dandy, but we need a domain name!

Freenom is an amazing little website offering year long subscriptions without the need for registration, to free domain names, such as myfreetestsite.tk or Miketurcotteisawesome.tk

Feel free to register a domain name to use for your website! You will need a basic understand of how to point your domain name to your sever using DNS. I found a handy little website specifically using freenom, showing how to do that in about 30 seconds.

Once that is done, people can then enter http://yournamehere.tk (or whatever your domain name is) and visit your website.

What are your thoughts? Ever had the desire to put something up on the internet? Would tutorials like this be of interest? Give me some feedback in the comments!

About Mike Turcotte

Mike Turcotte is a Journalism Student at Conestoga College. Mike loves working with Computers in his spare time, focusing on Systems Administration and Programming.