Setting up a static website with TierHive
TierHive is a Virtual Private Server (VPS, basically *nix box in the cloud) provider that is very affordable. A “micro” instance (128 megs of RAM and “Economy” CPU) costs $0.10 per month. I have a 1 vcpu 2G RAM instance that will cost about $2.50 a month.
One catch is that you don’t get an IPV4 address, so for accessing the host:
- You SSH to a special port that I’m guessing uniquely identifies your account.
- If you want to serve web traffic, the recommended way to do that is via their HAProxy service which can manage your SSL cert an proxy traffic to an HTTP server running on port 80 of your VPS.
- Or you can connect over IPV6.
They also have a static hosting offering that I haven’t looked into yet.
Hosting a website with TierHive HAProxy and VPS
- Get a VPS. This will be your “backend”. You can of course use it for other things in addition to a HAProxy backend. You can also configure multiple backends, but that would have been overkill for my purpose.
- Go to the HAProxy menu and add a new domain. You’ll get info for a TXT record, create that with your DNS manager. This just proves to TierHive that you do in fact own/control the relevant domain.
- Once verified, configure the backend: you’ll choose the VPS you set up in step 1.
- Next, click on the “Web server config” button and choose the option that suits you. In my case I went with a static nginx site. You’ll get a path to where the files on the VPS can live, and sample configuration. Use this sample config to set up nginx on the VPS, then get your files onto the VPS somehow. I used the ansible playbook shared below. It assumes that a) you have a folder on your local filesystem (could be a git repo, but not necessary) with
nginx.confat the root, and your actual HTML files in apublic_htmlfolder. ReplaceYOURDOMAIN.COMwith your actual domain, e.g.coolsite.biz. Note that you absolutely do not need to get the nginx config from TierHive: all you really have to do at this point is get a webserver serving something at port 80, which is what their HAProxy service expects. Their config generator provides options for nginx/apahce and php, node, or static html but you could run whatever webserver in whatever language you want, as long as it serves HTML over port 80. - You’ll probably want to enable www for your domain as well, so do that now. You should now be able to access your site over unencrypted HTTP. (Unless you have previously served this domain elsewhere and had HSTS enabled, in which case attempting to visit your new site will result in your browser complaining about SSL errors.)
- Next, still from the HAProxy configuration page, click the button to set up SSL. This may take a few minutes, took 5-6 for me. They will generate (and manage auto-renewal of) an SSL cert for you; this lives on their HAProxy server but you have the option to download it yourself as well, which would make it easier if you need to move off TierHive and want to avoid downtime.
- You’re done! You should now be able to load your new site.
---
- name: Install and configure nginx (Debian/Ubuntu)
hosts: vps
become: true
vars:
site_name: YOURDOMAIN.COM
site_root: "/var/www//html"
repo_root: "/.."
tasks:
- name: Install nginx (refreshing the apt cache when stale)
ansible.builtin.apt:
name: nginx
state: present
update_cache: true
cache_valid_time: 3600
- name: Ensure site root exists
ansible.builtin.file:
path: ""
state: directory
mode: "0755"
- name: Deploy website files
ansible.builtin.copy:
src: "/public_html/"
dest: "/"
mode: preserve
- name: Deploy nginx site config
ansible.builtin.copy:
src: "/nginx.conf"
dest: "/etc/nginx/conf.d/.conf"
mode: "0644"
notify: Reload nginx
- name: Validate nginx configuration
ansible.builtin.command: nginx -t
changed_when: false
- name: Ensure nginx is enabled and started
ansible.builtin.service:
name: nginx
state: started
enabled: true
handlers:
- name: Reload nginx
ansible.builtin.service:
name: nginx
state: reloaded
So far this has worked quite well for me.
The TierHive VPS itself, compared to the ones I run on other providers, seems more subject to random CPU spikes, but has certainly been stable enough for a small static website.