Hosting a static site on a VPS (Part 3)

Creating an Nginx configuration for your site

Posted on 2017-08-17

The big picture

As I mentioned in the previous post, you'll need to create a configuration file for each website you want to host. The configuration file will contain information on where the website lives on your server, among other things. I'll show you how to write a basic one and use it to make your website live!

A very simple example website

So simple, it's almost as easy as "import antigravity"!

I'll use a really basic "Hello, World" kind of website as an example website. Let's call it vincentchov.com and all it is is a single HTML file that says "Hello World!". Create a folder called "vincentchov.com" (or whatever your domain name is): (mkdir ~/vincentchov.com) and inside it, create an HTML file called index.html and have it contain <a>Hello World!</a>.

Finding a place for your static site to live

on your server, among other things. The default folder where Nginx assumes you'll store your websites is at /var/www/html and while you can change that, I'll stick to convention so my advice applies better when you read other people's guides. Provided you already made the vincentchov.com folder in your Home folder, move it to /var/www/html, which will need sudo permissions:
sudo mv ~/vincentchov.com /var/www/html. Awesome! Now let's write a config file so Nginx actually knows what to do with the site!

Nginx configuration to point to the site

We'll do it live!