Host Your Own Blog At Home
Tao RenPrerequisites
- Linux box, e.g. Ubuntu 18
- Domain name, e.g. https://tao.ren
- DDNS, i.e Dynamic DNS, is a dynamic IP address to be aliased to a static hostname, allowing a computer on the network to be more easily accessible from the Internet.
Overview
If you have a Linux box at home, you can use it to host your own blog, which could be generated by Jekyll.
-
Setup your Linux box
- Network
- Setup your router
- Setup your DDNS
- Setup your domain name
- Blog
- Setup Jekyll envrionment
- Build your blog.
- HTTP Server & Certificate
Enjoy your blog http://tao.ren
Setup your Linux box
Setup your router
Your router should have port forwarding setting, most likely in Firewall section, make sure any incoming connections on port 80 & 443 are forwarded to your Linux box.
Setup your DDNS
If your router also support DDNS, make sure it is bound to your domain name: https://tao.ren.
Otherwise, try dynu, install DDClient on your Linux box, you are all set.
Setup your domain name
Your domain name provdier usually needs your custom nameservers. Put whatever your DDNS provider says.
For dynu, you could do
- NS1.dynu.com
- NS6.dynu.com
Setup Jekyll developement envrionment
Set Up a Jekyll Development Site
sudo apt-get update
sudo apt-get install ruby ruby-dev make git curl libssl-dev libreadline-dev zlib1g-dev autoconf bison build-essential libyaml-dev libreadline-dev libncurses5-dev libffi-dev libgdbm-dev
## make sure ruby version >= 2.3.0
ruby -v
gem install bundler
Build your blog
Clone you blog project, go into it.
bundle install
export LANGUAGE="en_US.UTF-8"
export LC_ALL="C.UTF-8"
export LANG="en_US.UTF-8"
bundel exec jekyll build
The static html blog website will be built in folder your-blog-root-directory/_site/
Setup NGINX
sudo apt install nginx
Make a new server block at /etc/nginx/sites-available/tao.ren:
sudo nano /etc/nginx/sites-available/tao.ren
Link the server blog to your blog, paste in the following configuration block, updated for our new directory and domain name:
server {
listen 80;
listen [::]:80;
root your-blog-root-directory/_site;
index index.html index.htm index.nginx-debian.html;
server_name tao.ren;
location / {
try_files $uri $uri/ =404;
}
}
Enable the file by creating a link from it to the sites-enabled directory:
sudo ln -s /etc/nginx/sites-available/tao.ren /etc/nginx/sites-enabled/
Setup Let’s Encrypt
Using Free Let’s Encrypt SSL/TLS Certificates with NGINX
Download and install the Let’s Encrypt Client
add-apt-repository ppa:certbot/certbot
sudo apt-get install python-certbot-nginx
Obtain the SSL/TLS Certificate
sudo certbot --nginx -d tao.ren
Automatic Renewal of Let’s Encrypt Certificates
crontab -e
Add the certbot command to run daily. In this example, we run the command every day at noon. The command checks to see if the certificate on the server will expire within the next 30 days, and renews it if so. The –quiet directive tells certbot not to generate output.
0 12 * * * /usr/bin/certbot renew --quiet
Restart nginx server
sudo service nginx restart
Enjoy
Your own blog hosted at home, http://tao.ren
🍻🍻🍻