Setting up a static website with nginx on Ubuntu 20.

1. Login to your remote VM through your SSH key and update/upgrade Ubuntu.

ssh -i keyname.key ubuntu@externalIPadress

sudo apt-get update

sudo apt-get upgrade

2. Install nginx.

sudo apt-get install nginx

3. Open the ports to start rceiving the response from the server. In order to do this, go to your server and manage security rules (add http and https rules). After that, you should be able to see the nginx welcome page when you type your cloud's external IP address into your search engine.

4. Create a directory where you are going to store your code.

sudo mkdir /var/www/files-dir

Create a test HTML file in this new directory.

touch index.html

Open it and write something like Hello world!

sudo nano index.html

5. Next, let's configure nginx to serve this test file instead of the default greeting. Go to nginx sites-available folder, and make a copy of the default file. The reason for this is you never want to mess with the original default file (trust me).

cd /etc/nginx/sites-available

sudo cp default default_copy

In the new copied file, change the root from /var/www/html to /var/www/files-dir.

6. Now we are about to do something fancy. We need to make an external link of the newly created file to the /sites-enabled directory.

ln -s /etc/nginx/sites-available/default_copy /etc/nginx/sites-enabled/default_copy

7.Next, delete the existing default file in the sites-enabled directory (do not confuse with sites-available). If you do not do that, nginx will be confused and spit red warnings at you as if you hacked the core or something, because apparently two files in the sites-enabled repository are too many for him.

sudo rm /etc/nginx/sites-enabled/default

8. Restart nginx.

sudo systemctl restart nginx

If problems occur, log them by typing the following:

sudo systemctl status nginx

If you (miraculously) encountered no problems, you should see your html page on the web, after you type your domain name in the search engine. You can go ahead now and read Part II of this tutorial.

If problems did occur, then rejoice at the amazing opportunity to look for a solution on the web and become more knowledgeable about what you are doing. But first, make sure to check my list of recommendations on the troubleshooting page. I might have encountered and solved the problem you are struggling with.