After some troubles with Heroku I decided to host my blog on a web server.

Setup

Last year, I rented a scaleway web server. This time, I used linode.I bought a domain name on ovh, this time on gandi.

I developed my blog on Jekyll.

So this post is about how to piece all this together.

Linode / Ubuntu

Linode is a SSD Cloud Hosting to deploy a Linux virtual servers very quickly.


I used the Web Server Nginx. The documentation of linode is really well done, it is worth reading.

Connect to my linode via SSH

Ubuntu is a free and open-source operating system and Linux distribution based on Debian.


  • After signing up, I provisioned my linode.
  • I choosed the Ubuntu Linux Distribution to deploy an image
  • The linode was then booted
  • I connected to my linode via SSH
    • The public IP is in the dashboard
    • I entered ssh root@PUBLIC_IP in the terminal
    • I had an authenticity warning as this was the first time connecting to my Linode (so, it is normal)
    • I entered the password I created for the root user
    • Then the SSH client initiated the connection and opened a terminal

This is a important command to remember, as it is used to connect to the web server in the command line ! Each time, I try to establish the connection, my password is required.

ssh root@PUBLIC_IP


Install Software Updates

I installed the software updates. This should be performed regularly as it applies the latest security patches and bug fixes:

apt-get update && apt-get upgrade

Set the hostname and the Timezone

hostame:

echo "example_hostname" > /etc/hostname
hostname -F /etc/hostname

with the name I choosed for the example_hostname

timezone:

dpkg-reconfigure tzdata

Nginx

NGINX is open source software for web serving, reverse proxying, caching, load balancing, media streaming, and more. It started out as a web server designed for maximum performance and stability.


Install Nginx

sudo apt update
sudo apt install nginx

Set up Server access

I logged in to my SSH

ssh root@PUBLIC_IP

I created a user with permission to deploy

sudo adduser deploy
sudo adduser deploy sudo

I copied my SSH keys to the server

ssh-copy-id deploy@PUBLIC_IP

Note: I had to enter this command to make it work ssh-keygen -t rsa

To check if it worked, I logged in with it and quit right after. 👌🏻

ssh deploy@PUBLIC_IP

deploy site on web server

Ok, so I am connected to the web server with ssh root@PUBLIC_IP, I can navigate into the Nginx:

>> cd /etc/nginx

I see these directories (among others)

>> ls
sites-available  sites-enabled  snippets

I first copied the default file and then navigated into it.

cp sites-available/default ~/
cat sites-available/default

The root of my server is:

root /var/www/html;

If I paste the PUBLIC_IP into the browser, I can see the Welcome Page from Nginx.

To access the source code in my web server, I go to the directory: cd /var/www/html/

/var/www/html# ls
index.nginx-debian.html

And reading the file that’s inside, I see that this is the source code from the welcome page I saw in the browser.

I can write any text into the index file and check it in the browser.

  rm index.nginx-debian.html
  cat > index.html
  <h1> hello </h1>

But, yeah, it would be better to have my blog over here instead of “Hello” :)

So back to deploying my website. I went to:

cd /etc/nginx/sites-enabled
nano default

and changed the line root /var/www/html; to have root /home/deploy/your_blog_name/_site;

Don’t forget the root and the ; 🙀

Note: nginx -t and sudo nginx -t are very useful methods to see if everything went ok with the configuration file.

>> nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

Generate the _site build folder

In my console, I ran this command: bundle exec jekyll build

Transfer the _site directory to the server

In my console, inside my blog directory:

`rsync -a _site deploy@PUBLIC_IP:/home/deploy/your_site_name`


This is an important command as it is used to export my local posts (inside _site) to the web server.

Then going back to the Nginx console,

I can now see my posts here /home/deploy/your_site_name/_site

I can use sudo nginx -s reload to watch changes live.

Parenthesis: Gandi

So as I said, I bought a domain name on Gandi. Then I added a A type DNS with the PUBLIC_IP. And added a redirection for the www

Back to Nginx configuration file

cd /etc/nginx/sites-enables/
nano default

I updated the server_name with my domain name on this line

server_name your_domain.com;

saved and sudo nginx -s reload

This is live in seconds

Alt Text


Updated: