Genesis Cloud has its greatest advantages for Deep Learning Training, Rendering and other burst workloads. However, that doesn't mean you can't run a lot of other cool stuff on it, too.
In this tutorial, I'll show you how to set up an nginx server on Genesis Cloud to host a static Website. Nginx can be used for many other things like reverse proxies, load balancing and is typically used to server more than just one single webpage, but this should allow you to get started with Nginx.
For the purpose of the 'll assume the following in the next steps:
- You're familiar with the basics of Linux CLI
- Your static website is under the domain www.intuitive.run
- You have no experience with NGINX
Step 1: Create an instance and ssh into it
Follow our guide on how to create an Ubuntu instance and connect to it via ssh.
Make sure the default ports 22 (SSH), 80 (HTTP) and 443 (HTTPS) are open.
Step 2: Point your domain name to your new instance
Create an A record in your hosting provider's DNS settings that contains your instance's public IP. For the example of Google Domains this looks like this:
An example of DNS settings for google domains
Optionally, you can also set a CNAME record to register the subdomain "www".
Step 3: Install Nginx
For Ubuntu, simply run:
$ sudo apt update; sudo apt install nginx |
Check if your installation was successful by inserting the public IP address of you instance into your browser. It should show the nginx welcome screen. This is index.nginx-debian.html that Nginx is configured to serve by default under /var/www/html.
Correct configuration of nginx
Step 4: Move your website to the new webserver
NGINX can only deliver your site if it has your static website's source files (typically *.html, *.css and *.js files), so let's move them to the right place.
Generally, NGINX expects your static website files in a specific directory, in our case we'll chose /var/www/ as that place. Therefore, cd into that directory and create a new directory with the name of your domain "intuitive.run":
~$ cd /var/www/
/var/www$ sudo mkdir intuitive.run
/var/www$ cd intuitive.run
/var/www/intuitive.run$
In order to be able to copy your files, you need to also adjust the permissions of the new folder so everyone has full access:
/var/www$ sudo chmod 755 intuitive.run/
Next, copy you website's files from your local machine into the new folder on the webserver via the "secure copy", scp command. Make sure that you are running this command from inside the local folder where your website source files are and that you adjust the public IP address to that of your own instance on Genesis Cloud:
/intuitive.run$ scp -r * ubuntu@194.61.20.151:/var/www/intuitive.run
After running scp successfully, you should see something like this:
The terminal shows the copied files and details about the process
Step 5: Configure nginx via server block file to serve your site
In order to make your site available, you need to adjust some configurations. These configurations tell Nginx how to serve the site and are written in so-called "server bock files". As we're only serving one site in this example, we only need one server block file.
To get started, cd into /etc/nginx/:
$ cd /etc/nginx/
In there, you'll find two folders (among others):
- sites-available contains the individual configuration files, aka "server block files" for all sites served by your webserver
- sites-enabled contains links to these configuration files and therefore determines which website is actually served by NGINX.
So, let's first create a the server block file for our static webpage named intuitive.run in the directory sites-available. You will need sudo privileges for that:
To use sudo privilges start your command with "sudo "
Paste in the following configuration content (replace intuitive.run with your own domain name):
server {
listen 80;
listen [::]:80;
root /var/www/intuitive.run;
index index.html;
server_name intuitive.run www.intuitive.run;
location / {
try_files $uri $uri/ =404;
}
}
This is the server block file. It tells NGINX the following:
- root: to serve a website with files in the folder: /var/www/intuitive.run
- that the main index page is "index.html"
- requests for intuitive.run and the subdomain www.intuitive.run should be served by this server block
Step 6: Enable your server block file
Now that we have created our server block file, we need to add a link to this file in sites-enabled in order to enable it. Nginx reads the links in that folder during startup.
Create the link with the ln -s <SOURCE_FILE> <DESTINATION_FILE> command:
$ sudo ln -s /etc/nginx/sites-available/intuitive.run /etc/nginx/sites-enabled/intuitive.run
We now have two server blocks enabled:
- intuitive.run: Will respond to requests for intuitive.run and www.intuitive.run
- default: Will respond to any requests on port 80 that do not match the other block (the respective server block fine has the so called default_server option in it. You can also add this to the intuitive.run server block but the you'll need to remove that option from the default block.)
The terminal after enabling the server blocks
Step 7: Test and restart nginx
Next, make sure that there are no syntax errors in any of your Nginx files by running:
$ sudo nginx -t
If this is what you should see:
The terminal shows that the configuration was successful
it means no problems were found and you can go ahead and restart Nginx to enable your changes:
$ sudo systemctl restart nginx
If you now visit your domain name: http://intuitive.run/, you should see your site!