Setup Hugo Blog on Vps
tl;dr:
Table of contents:
Hi, in this post im going to setup a blog using hugo on a private vps. Here are the stack that i will use:
- for domain and ssl im using cloudflare
- im using a plain base ubuntu vps running nginx and hugo on top of docker.
- github actions CICD to build and deploy the site to the vps. it wont be in this article but im planning to have it.
Buy a domain and VPS
Buy a domain from registrar and a vps from a provider. im running ubuntu on my contabo vps.
configure this on the cloudflare dashboard:
- setup ssl with full strict mode on cloudflare
- generate origin certificate on cloudflare and put it in the vps
examplesite.crt and examplesite.key
. Make sure to generate both your domain and wildcard cert. - point your domain dns to the vps ip
a little about certs on cloudflare. I chose to use cloudflare’s origin certificate because it’s just easier to setup than let’s encrypt. it lasts for up to 15 years and its free.
Setup nginx, cert, and hugo
Here’s the deployment structure for the vps:
/srv/certs : certificates for the domain
/srv/http : static files or hugo project
Put the hugo project in : /srv/http/examplesite.com/
Put both origin certificate and key in : /srv/certs/examplesite.com/
Setup Nginx:
sudo apt install nginx
touch /etc/nginx/conf.d/examplesite.com.conf
examplesite.com.conf
server {
listen 80;
server_name examplesite.com www.examplesite.com;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl;
server_name examplesite.com www.examplesite.com;
ssl_certificate /srv/certs/examplesite.com/cert.pem;
ssl_certificate_key /srv/certs/examplesite.com/key.pem;
root /srv/http/examplesite.com;
index index.html;
location / {
try_files $uri $uri/ =404;
}
location /static/ {
autoindex on;
}
}
restart nginx with systemctl restart nginx
and now it works!